Create an endpoint that allows users to delete a product from the existing inventory database by its ID. This feature should validate the request and respond with appropriate success or error messages.
Acceptance Criteria:
Endpoint Creation:
A DELETE endpoint /api/products/{id} is created, where {id} is the product's unique identifier.
Request Parameter:
The endpoint accepts a path variable id (Long, required).
Validation:
Check if the product with the given ID exists in the database.
If the product does not exist, return an appropriate error response.
Database Interaction:
On successful validation, the product should be removed from the inventory database.
Use JPA/Hibernate for database interactions.
Response:
On success, return HTTP status 204 (No Content).
If the product does not exist, return HTTP status 404 (Not Found).
Error Handling:
Handle database errors and return appropriate responses (e.g., 500 Internal Server Error).
Tasks:
[ ] Update the ProductRepository interface to include a method for deleting by ID.
[ ] Implement the ProductService method for deleting a product.
[ ] Create a ProductController method to handle the DELETE request.
[ ] Write unit tests for service methods related to deletion.
[ ] Write integration tests for the DELETE API endpoint.
Description:
Create an endpoint that allows users to delete a product from the existing inventory database by its ID. This feature should validate the request and respond with appropriate success or error messages.
Acceptance Criteria:
Endpoint Creation:
/api/products/{id}
is created, where{id}
is the product's unique identifier.Request Parameter:
id
(Long, required).Validation:
Database Interaction:
Response:
Error Handling:
Tasks:
ProductRepository
interface to include a method for deleting by ID.ProductService
method for deleting a product.ProductController
method to handle the DELETE request.