Problem
Design APIs for Product Catalogue
1. Core Product APIs (CRUD)
- POST
/productscreates a new product in the catalog. The request body should include product details such as name, description, price, category, stock quantity, etc. - GET
/productsretrieves a list of products. Should support pagination, sorting (by price, name), and filtering (by category, brand, reviews). - GET
/products/{productId}retrieves detailed information about a specific product identified byproductId. - PUT
/products/{productId}Updates all the information for an existing product (a full replacement). - PATCH
/products/{productId}updates specific fields of an existing product (a partial update). - DELETE
/products/{productId}removes a product from the catalog.
2. Category Management
- POST
/categoriescreates a new product category - GET
/categoriesretrieves a list of all categories. Hierarchical structure should be supported. - GET
/categories/{categoryId}retrieves details of a specific category. - GET
/categories/{categoryId}/productsretrieves all products within a specific category. - PUT
/categories/{categoryId}updates category details. - DELETE
/categories/{categoryId}removes a category.
3. Inventory Management
- PUT
/products/{productId}/inventoryadds stock for a specific product. - GET
/products/{productId}/inventoryretrieves current stock levels for a specific product. - DELETE
/products/{productId}/inventoryremoves stock information for a specific product.
4. Search Functionality
- GET
/search?q={query}allows searching for products using query parameters such as keywords, category, price range, brand, and ratings. Should support pagination and sorting.
5. Pricing Management
- PUT
/products/{productId}/priceupdates the price of a specific product. - GET
/products/{productId}/priceretrieves the current price of a specific product.
6. Reviews and Ratings
- POST
/products/{productId}/reviewsadds a review for a specific product. - GET
/products/{productId}/reviewsretrieves all reviews for a specific product. Should support pagination.
Data Models:
{
"Product": {
"id": "string",
"name": "string",
"description": "string",
"price": "number",
"categoryId": "string",
"brand": "string",
"stockQuantity": "number",
"createdAt": "timestamp",
"updatedAt": "timestamp"
},
"Category": {
"id": "string",
"name": "string",
"parentCategoryId": "string|null",
"createdAt": "timestamp",
"updatedAt": "timestamp"
},
"Review": {
"id": "string",
"productId": "string",
"userId": "string",
"rating": "number",
"comment": "string",
"createdAt": "timestamp"
}
}