Create an endpoint that allows users to add new products to the existing inventory database. This feature should validate the input and respond with appropriate success or error messages.
Acceptance Criteria:
Endpoint Creation:
A POST endpoint /api/products is created.
Request Payload:
The request should accept a JSON body containing:
name (String, required)
description (String, optional)
price (Decimal, required)
quantity (Integer, required)
Validation:
Ensure that:
name is not empty.
price is a positive number.
quantity is a non-negative integer.
Database Interaction:
On successful validation, a new product should be added to the inventory database.
Use JPA/Hibernate for database interactions.
Response:
On success, return HTTP status 201 (Created) with the newly created product details.
On validation failure, return HTTP status 400 (Bad Request) with error messages.
Error Handling:
Handle database errors and return appropriate responses (e.g., 500 Internal Server Error).
Tasks:
[x] Create the Product entity class.
[x] Set up the ProductRepository interface for database operations.
[x] Implement the ProductService for business logic.
[x] Create a ProductController to handle the POST request.
[x] Write unit tests for validation and service methods.
Description:
Create an endpoint that allows users to add new products to the existing inventory database. This feature should validate the input and respond with appropriate success or error messages.
Acceptance Criteria:
Endpoint Creation:
/api/products
is created.Request Payload:
name
(String, required)description
(String, optional)price
(Decimal, required)quantity
(Integer, required)Validation:
name
is not empty.price
is a positive number.quantity
is a non-negative integer.Database Interaction:
Response:
Error Handling:
Tasks:
Product
entity class.ProductRepository
interface for database operations.ProductService
for business logic.ProductController
to handle the POST request.