Product Module - API Contract & Business Logic
1. Create Product
Method: POST
Endpoint: /api/products
Access: Auth (Vendor/Admin)
Controller:
- Extract vendorId from session/request
- Call service
Service:
- Generate slug & SKU
- Use transaction to create product, images, variants
Response: 201 Created
2. Get All Products
Method: GET
Endpoint: /api/products
Access: Public
Features:
- Pagination (page, limit)
- Filters (category, brand, price)
- Search (q)
- Sorting (price, newest)
Response: 200 OK with metadata
3. Get Product Detail
Method: GET
Endpoint: /api/products/:slug
Access: Public
Includes:
Category, Brand, Images, Variants, Reviews
Response: 200 OK
4. Update Product
Method: PATCH
Endpoint: /api/products/:id
Access: Admin/Owner
Logic:
- Partial update
- Image sync (delete + create)
Response: 200 OK
5. Stock Update
Method: PATCH
Endpoint: /api/products/:id/stock
Access: Vendor (Owner)
Logic:
- Atomic increment/decrement
Response: 200 OK
6. Delete Product
Method: DELETE
Endpoint: /api/products/:id
Access: Admin/Owner
Logic:
- If orders exist → Soft Delete
- Else → Hard Delete
Response: 204 No Content