쇼핑몰 구현 프로젝트

[쇼핑몰 구현 프로젝트] 02. API, DB 설계

binning 2024. 6. 7. 11:30

MERN 풀스택을 공부하고 나서 어떻게 코드를 짜야할 지 틀을 잡을 수 있었다.

공부한 내용으로 프로젝트 설계를 처음부터 다시 진행하기로 했다.

 

1. Database

 

- User

  • name, email, password, address, phone_number: String
  • admin: Boolean
  • cart, purchase_history: [ Product_id 연결 ]

- Product

  • name, description, image, category: String
  • price, stock: Number

- Review

  • content: String
  • star: Number
  • user: User_id 연결
  • product: Product_id 연결

 

2. Frontend

 

- 사용자

Route Content Is login
/ Home (List of All products) O / X
/login Login form X
/signup Signup form X
/category/:cid List of products in a category O / X
/product/:pid Information of a product O / X
/user/:uid Information of a user(My page) O
/cart/:uid List of products in cart O
/edit/:uid Edit user information form O
/history/:uid Show purchase history O
/review/:uid Show reviews of specific user O

 

- 관리자

Route Content
/product/new Create new product form
/product/edit/:pid Edit product form

 

3. Backend

 

- /api/users

Method Route Content
GET /:uid Get a user's information
POST /signup Create new user + Login
POST /login Login
POST /:uid Pay for products
PATCH /:uid Edit user information

 

- /api/products

Method Route Content
GET / Get all products
GET /:pid Get a specific product
GET /category/:cid Get products in category
POST / Create a new product
PATCH /:pid Edit a product
DELETE /:pid Delete a product

 

- /api/reviews

Method Route Content
GET /product/:pid Get reviews of a product
GET /user/:uid Get reviews of a user
POST / Create a review
DELETE /:rid Delete a review

 

- /api/carts

Method Route Content
POST /:uid/:pid Put a product in a cart
DELETE /:uid/:pid Delete a product from a cart
DELETE /:uid Delete all product from a cart