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.
- Getting Started
- Prerequisites
- Installing
- Complex Queries
- Running the Tests
- End to End Testing
- Coding Style Tests
- Built With
- Contributing
- Authors
- Acknowledgements
These instructions will get you a copy of the rails engine API up and running on your local machine for development and testing purposes.
- 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
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.
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
In order to run the test suite, run the following command:
rspec
- 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_date
selects 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
Please feel free to submit pull requests and suggestions to this repository. We would love your feedback.
- Thanks to our wonderful instructors at Turing