Skip to content

jdcarey128/rails-engine

Repository files navigation

Rails Engine

This API exposes fictional ecommerce data for item, merchant, and business inteligence endpoints. Most endpoints follow REST convention and all return a JSON response. See below for installation instructions and example queries.

Summary

Installation

To access the API endpoints, clone this repository (see here for more info) and run the following commands in your CLI:

  1. Install gem dependencies: bundle install
  2. Import data: bundle exec rake data:import
  3. Run local server: rails s

Querying Endpoints

It is recommended that you use Postman to perform API queries. To download the postman app, visit: this link. The root url for all queries is localhost:3000/api/v1 followed by the endpoint path specified below. Include an ID number of the resource for paths that require an :id (e.g. /merchant/1).

Note: when making POST or PATCH queries, make sure the raw body is sent as JSON.

request-body-as-json

Merchants

  1. List all merchants: GET `/merchants'
  2. Return specific merchant: GET /merchants/:id
  3. Create merchant: POST /merchants
    1. Within the body of the request, include:
           "name": "merchant name"
         } 
      
  4. Update merchant: PATCH /merchant/:id { "name": "new merchant name" }
  5. Delete merchant: DELETE /merchants/:id Note: a successful delete will not return rendered JSON.
  6. Return all items associated with a merchant: GET /merchants/:id/items
  7. Return a single merchant based on query parameters: GET /merchants/find?<attribute>=<value>
    1. Attributes include: name, created_at, and updated_at. Formating accepted for created_at and updated_at attributes is 'yyyy-mm-dd'.
  8. Return (20) merchants that match set of criteria: GET /merchants/find_all?<attribute>=<value>
    1. Above attributes for find are accepted.

Items

  1. List all items: GET `/items'
  2. Return specific item: GET /items/:id
  3. Create item: POST /items
    1. Within the body of the request, include:
           "name": "item name", 
           "description": "item description (optional)",
           "unit_price": "item price (in dollars)", 
           "merchant_id": "existing merchant id"
         }
      
  4. Update item: PATCH /items/:id
    1. Include any one, or more, of the attributes as listed above in the body of the request.
  5. Delete item: DELETE /items/:id Note: a successful delete will not return rendered JSON.
  6. Return the merchant associated with an item: GET /items/:id/merchants
  7. Return a single item based on query parameters: GET /items/find?<attribute>=<value>
    1. Attributes include: name, description, unit_price, merchant_id, created_at, and updated_at. Formating accepted for created_at and updated_at attributes is 'yyyy-mm-dd'.
  8. Return (20) items that match set of criteria: GET /items/find_all?<attribute>=<value>
    1. Above attributes for find are accepted.

Business Intelligence

  1. Return a variable number of merchants ranked by total revenue: GET /merchants/most_revenue?quantity=<number>
  2. Return a variable number of merchants ranked by total number of items sold: GET /merchants/most_items?quantity=<number>
  3. Return the total revenue for all merchants between two dates: GET /revenue?start=<start_date>&end=<end_date>
    1. Formating accepted for start_date and end_date is 'yyyy-mm-dd'
  4. Return the total revenue for a specific merchant: GET /merchants/:id/revenue

Example Queries

Creating A Merchant

Query:

creating-a-merchant

Result:

created-merchant-result

Creating An Item

Query (using merchant id above):

creating-an-item

Result:

created-item-result

Returning A Merchant's Items

Query:

merchant-items-query

Result:

merchant-item-result

Returning Top 10 Merchants With Most Revenue

Query:

top-10-most-revenue

Result (first three records):

first-three-most-revenue

Common Errors

Missing Parameter(s)

  1. You will receive an error message similar to the following if missing a parameter when creating a record:

missing-param-error

Non-existent Record

  1. When an id that does not exist in the database is used for a show request, you will receive the following error:

non-existent-record-error

Contact

Author: Joshua Carey LinkedIn

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published