Table of Contents generated with DocToc
The purpose of this project is to use Rails and ActiveRecord to build a JSON API which exposes the SalesEngine data schema.
This project uses the Ruby on Rails framework, which can be installed from here. Bundler is used to install the gems needed for this application.
In order to run this appication in the development environment, perform the following in the CLI:
bundle install
rake db:create db:migrate
rake import_csv
In order to spin-up the server, run: rails s
To view the JSON API endpoint, visit the path, ending with .json. For example, visiting http://localhost:3000/api/v1/merchants/random.json returns a random merchant.
For a given :resource (merchants, items, invoices, invoice_items, customers, transactions)...
GET /api/v1/:resourcereturns a list of all instances of a resourceGET /api/v1/:resource/:idreturns a resourceGET /api/v1/:resource/find?<parameters>returns a resource with the given (as params) attributesGET /api/v1/:resource/find_all?<parameters>returns a list of resources with the given (as params) attributesGET /api/v1/:resource/randomreturns a random instance of a resource
GET /api/v1/merchants/:id/itemsreturns a collection of items associated with that merchantGET /api/v1/merchants/:id/invoicesreturns a collection of invoices associated with that merchant from their known orders
GET /api/v1/invoices/:id/transactionsreturns a collection of associated transactionsGET /api/v1/invoices/:id/invoice_itemsreturns a collection of associated invoice itemsGET /api/v1/invoices/:id/itemsreturns a collection of associated itemsGET /api/v1/invoices/:id/customerreturns the associated customerGET /api/v1/invoices/:id/merchantreturns the associated merchant
GET /api/v1/invoice_items/:id/invoicereturns the associated invoiceGET /api/v1/invoice_items/:id/itemreturns the associated item
GET /api/v1/items/:id/invoice_itemsreturns a collection of associated invoice itemsGET /api/v1/items/:id/merchantreturns the associated merchant
GET /api/v1/transactions/:id/invoicereturns the associated invoice
GET /api/v1/customers/:id/invoicesreturns a collection of associated invoicesGET /api/v1/customers/:id/transactionsreturns a collection of associated transactions
GET /api/v1/merchants/most_revenue?quantity=xreturns the top x merchants ranked by total revenueGET /api/v1/merchants/most_items?quantity=xreturns the top x merchants ranked by total number of items soldGET /api/v1/merchants/revenue?date=x returnsthe total revenue for date x across all merchants
GET /api/v1/merchants/:id/revenuereturns the total revenue for that merchant across successful transactionsGET /api/v1/merchants/:id/revenue?date=xreturns the total revenue for that merchant for a specific invoice date xGET /api/v1/merchants/:id/favorite_customerreturns the customer who has conducted the most total number of successful transactions
GET /api/v1/items/most_revenue?quantity=xreturns the top x items ranked by total revenue generatedGET /api/v1/items/most_items?quantity=xreturns the top x item instances ranked by total number soldGET /api/v1/items/:id/best_dayreturns the date with the most sales for the given item using the invoice date. If there are multiple days with equal number of sales, return the most recent day.
GET /api/v1/customers/:id/favorite_merchantreturns a merchant where the customer has conducted the most successful transactions
Rspec-Rails is used for testing. Factory_Bot is used to create test data.
In order to run tests, perform the following:
rake db:test:prepare
rspec
Anna Lewis (@anlewi5) Nico Lewis(@nico24687)
