Skip to content

A 35 endpoint API that takes sanitized data from large company and runs analytics on it

Notifications You must be signed in to change notification settings

lnchambers/rails_engine

Repository files navigation

Rails Engine

This project utilizes Ruby on Rails and ActiveRecord to build a JSON API which exposes sales data selected from Etsy. This api serves up business analytics, relational endpoints, and record endpoints. For a full explanation of the endpoints, look at this endpoint explanation. Below is a database schema explaining the relationships between each endpoint: merchant, customer, items, invoices, transactions and invoice items.

schema

Table of Contents

Getting Started

These instructions will get you a copy of the rails engine API up and running on your local machine for development and testing purposes.

Prerequisites

  • Ruby, version 2.5
  • Rails, version 5.1.5
  • Puma, version 3.7
  • Rspec-Rails

After cloning down this repository, change into the directory rales_engine and run:

bundle

Installing

To setup the database necessary for this API, run the following commands:

rails db:create
rails db:migrate
rake import_csv

To import a specific csv for a model, see this explanation.

Complex Queries

To view some complex data querying run the following:

rails c

After the console is open:

Items.most_items
Items.most_revenue
Transaction.total_revenue_by_date("2012-03-16")
Merchant.first.customers_with_pending_invoices

Running the tests

In order to run the test suite, run the following command:

rspec

Break down into end to end tests

  • Simple Model Test:

The following test ensures that an invoice has a status and all the appropriate associated data.

rspec spec/models/invoice_spec.rb
  • Complex Model Test:

The following test makes use ten separate factorybot factories to ensure that a merchant has a name and that it has all the appropriate associations(e.g., has many invoices_items through invoices). The class method .most_revenue selects the top merchants ranked by revenue. The class method .most_items selects the top merchants ranked by total number of items sold. The instance method #top_revenue_by_dateselects the total revenue for a specific merchant on an invoice date.

rspec spec/models/merchant_spec.rb
  • Simple Request Test:

The following test ensures that all invoices associated with a specific customer are returned.

rspec spec/requests/api/v1/customers/invoices_request_spec.rb
  • Complex Request Test:

When a request goes to the invoice_items record endpoint, a user can find an invoice item by id, unit_price, quantity or all invoice items matching a unit price or quantity.

rspec spec/requests/api/v1/invoice_items/invoice_items_request_spec.rb

Built With

Contributing

Please feel free to submit pull requests and suggestions to this repository. We would love your feedback.

Authors

Acknowledgments

  • Thanks to our wonderful instructors at Turing

About

A 35 endpoint API that takes sanitized data from large company and runs analytics on it

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published