Skip to content

Latest commit

 

History

History
90 lines (74 loc) · 2.77 KB

REQUIREMENTS.md

File metadata and controls

90 lines (74 loc) · 2.77 KB

API Requirements

The company stakeholders want to create an online storefront to showcase their great product ideas. Users need to be able to browse an index of all products, see the specifics of a single product, and add products to an order that they can view in a cart page. You have been tasked with building the API that will support this application, and your coworker is building the frontend.

These are the notes from a meeting with the frontend developer that describe what endpoints the API needs to supply, as well as data shapes the frontend and backend have agreed meet the requirements of the application.

API Endpoints

Products

  • Index - ([GET] /api/products)
  • Show - ([GET] /api/products/1)
  • Create [token required] - ([POST] /api/products)
  • Update [token required] - ([PUT] /api/products/1)
  • Delete [token required] - ([DELETE] /api/products/1)
  • [OPTIONAL] Top 5 most popular products
  • [OPTIONAL] Products by category (args: product category)

Users

  • Index [token required] - ([GET] /api/users)
  • Show [token required] - ([GET] /api/users/1)
  • Update [token required] - ([PUT] /api/users/1)
  • Delete [token required] - ([DELETE] /api/users/1)
  • Create [token required] - ([POST] /api/users)

Orders

  • Index [token required] - ([GET] /api/orders)
  • Show [token required] - ([GET] /api/orders/1)
  • Update [token required] - ([PUT] /api/orders/1)
  • Delete [token required] - ([DELETE] /api/orders/1)
  • Create [token required] - ([POST] /api/orders)
  • Current Order by user (args: user id)[token required] - ([GET] /api/dashboard/user-order/1)
  • Checkout an order- ([PUT] /api/users/1/checkout/1)
  • [OPTIONAL] Completed Orders by user (args: user id)[token required]

Data Shapes

Product

  • id
  • name
  • price
  • [OPTIONAL] category
CREATE TABLE IF NOT EXISTS products(
    id SERIAL PRIMARY KEY,
    name VARCHAR(155) NOT NULL,
    price NUMERIC NOT NULL
);

User

  • id
  • firstName
  • lastName
  • password
CREATE TABLE IF NOT EXISTS users (
    id SERIAL PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    firstName VARCHAR(155) NOT NULL,
    lastName VARCHAR(155) NOT NULL,
    password_digest CHAR(60)
);  

Orders

  • id
  • id of each product in the order
  • quantity of each product in the order
  • user_id
  • status of order (active or complete)
CREATE TABLE IF NOT EXISTS orders (
    id SERIAL PRIMARY KEY,
    status VARCHAR(20), 
    user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE
);


CREATE TABLE IF NOT EXISTS order_products(
    id SERIAL PRIMARY KEY,
    quantity INTEGER,
    order_id  BIGINT NOT NULL REFERENCES orders(id) ON DELETE CASCADE ON UPDATE CASCADE,
    product_id BIGINT NOT NULL REFERENCES products(id) ON DELETE CASCADE ON UPDATE CASCADE
);