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. I have been tasked with building the API that will support this application, and I built a sample frontend APP too.
These are the notes that describe what endpoints the API needs to supply, as well as data shapes the frontend and backend have agreed to meet the requirements of the application.
- Index
- Show
- Create [token required]
- Top 5 most popular products
- Products by category (args: product category)
- Index [token required]
- Show [token required]
- Create N[token required]
- Current Order by user (args: user id)[token required]
- [OPTIONAL] Completed Orders by user (args: user id)[token required]
- id
- name
- price
- [OPTIONAL] category
- id
- firstName
- lastName
- password
- id
- id of each product in the order
- quantity of each product in the order
- user_id
- status of order (active or complete)
enviroment variable used :
POSTGRES_HOST=localhost
POSTGRES_DB=my_db
POSTGRES_TEST_DB=my_db_test
POSTGRES_USER=postgres
POSTGRES_PASSWORD="1234"
POSTGRES_DBPORT=5432
ENV=dev
BCRYPT_PASSWORD=secretpassword
SALT_ROUNDS=10
TOKEN_SECRET=MYSECRET
PORT=8080
npm install -g db-migrate
npm i db-migrate db-migrate-pg
db-migrate create products_table --sql-file
db-migrate create users_table --sql-file
db-migrate create Orders-table --sql-file
db-migrate create OrderDetails-table --sql-file
npm run db-migrate-up
(RUN down CMD WHEN NEEDED)
npm run db-migrate-down
IN Jasmine.json SET RANDOM=FALSE;
npm run test
npm run dev-server
token =eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjo0LCJmaXJzdG5hbWUiOiJhaG1lZCIsImxhc3RuYW1lIjoibW9oZSIsInBhc3N3b3JkIjoiJDJiJDEwJGFkUXVvL05DdjY4SnA0NENISFguc08zWlZ1Q1JGZUtaOFVER0VuSC9pYkdwVUtyd0tTZ095IiwidXNlcm5hbWUiOiJhaG1lZGVyZmFuIn0sImlhdCI6MTY3MDk0OTQ0Nn0.4V-sSzRkmSYw4W4ThE0QOcgMLOEow3il6zFaCbzy4o0
POST http://localhost:8080/Signup?id=4&firstname=ahmed&lastname=mohe&password=555&username=ahmederfan
POST http://localhost:8080/Signup?firstname=ahmed&lastname=mohe&password=555&username=ahmederfan
GET http://localhost:8080/authenticate?username=ahmederfan&password=555
GET http://localhost:8080/user
GET http://localhost:8080/user/:userID
POST http://localhost:8080/Products?id=3&name=third&price=300
GET http://localhost:8080/Products
GET http://localhost:8080/Products/3
POST http://localhost:8080/user/:userID/Order/:orderID/product
Note: Add the following data in the body inputs to add product details to the cart of order 1 for testing
{ "quantity":"5", "productid":"3" }
GET http://localhost:8080/user/:userID/Order
POST http://localhost:8080/Order/:orderID/product
Note: Add the following data in the body inputs to add product details to the cart of order 1 for testing
{ "quantity":"5", "productid":"3" }