Skip to content

Latest commit

 

History

History
132 lines (91 loc) · 2.78 KB

REQUIREMENTS.md

File metadata and controls

132 lines (91 loc) · 2.78 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 Endpoints

  • Index all products : [GET] '/products'

  • Show product by Id: [GET] '/products/1'

  • Create new product (token required): [POST] '/products/new'

{ "name": "product", "price": 200, "category": "phone" }

  • Delete product by Id: [DELETE] '/products/1'

Users Endpoints

  • Index all users (token required): [GET] '/users'

  • Show user by Id (token required): [GET] '/users/1'

  • Create new user (token required): [POST] '/users/new'

{ "username": "sarah22", "firstName": "sarah", "lastName": "hassan", "password": "12345", }

  • Auth user (token required): [POST] '/users/signin' { "username": "sarah22", "password": "12345" }

  • Delete product by Id (token required): [DELETE] '/users/1'

Orders Endpoints

  • Index all orders : [GET] '/orders'

  • Show order by Id: [GET] '/products/1'

  • Create new order (token required): [POST] '/orders/new'

{ "status": "active", "user_id": 8 }

  • Delete order by Id: [DELETE] '/orders/1'

  • Current Order by user (token required): [GET] 'orders/user/1'

  • Add new product to order : [POST] 'orders/1/products'

{ "product_id": 3, "quantity": 200 }

Data Shapes

Product

  • id
  • name
  • price
  • [OPTIONAL] category

Table: products( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, price INTEGER NOT NULL, category VARCHAR(100) );

User

  • id
  • firstName
  • lastName
  • password

Table: Users( id SERIAL PRIMARY KEY, username VARCHAR(100) NOT NULL, firstName VARCHAR(100) NOT NULL, lastName VARCHAR(100) NOT NULL, password VARCHAR(100) NOT NULL );

Orders

  • id
  • id of each product in the order
  • quantity of each product in the order
  • user_id
  • status of order (active or complete)

Table: Orders( id SERIAL PRIMARY KEY, status VARCHAR(100) NOT NULL, user_id INTEGER REFERENCES users(id) NOT NULL );

Order_products

  • id
  • quantity of each product in the order
  • order id
  • id of each product in the order

Table: Order_products( id SERIAL PRIMARY KEY, quantity INTEGER NOT NULL, order_id INTEGER REFERENCES orders(id) NOT NULL, product_id INTEGER REFERENCES products(id) NOT NULL )