Problem

Design APIs for Product Catalogue

1. Core Product APIs (CRUD)

  • POST /products creates a new product in the catalog. The request body should include product details such as name, description, price, category, stock quantity, etc.
  • GET /products retrieves a list of products. Should support paginationsorting (by price, name), and filtering (by category, brand, reviews).
  • GET /products/{productId} retrieves detailed information about a specific product identified by productId.
  • 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 /categories creates a new product category
  • GET /categories retrieves a list of all categories. Hierarchical structure should be supported.
  • GET /categories/{categoryId} retrieves details of a specific category.
  • GET /categories/{categoryId}/products retrieves all products within a specific category.
  • PUT /categories/{categoryId} updates category details.
  • DELETE /categories/{categoryId} removes a category.

3. Inventory Management

  • PUT /products/{productId}/inventory adds stock for a specific product.
  • GET /products/{productId}/inventory retrieves current stock levels for a specific product.
  • DELETE /products/{productId}/inventory removes 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}/price updates the price of a specific product.
  • GET /products/{productId}/price retrieves the current price of a specific product.

6. Reviews and Ratings

  • POST /products/{productId}/reviews adds a review for a specific product.
  • GET /products/{productId}/reviews retrieves 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"
	}
}