Category Delete API Endpoint
Opened this issue · 0 comments
Pythonian commented
Description
Develop an endpoint to handle requests to soft delete a category. Instead of removing the category from the database, this will set a flag to indicate that the category is deleted.
Acceptance Criteria
- The endpoint allows soft deletion of a category by setting its
is_deletedflag toTrue. - The endpoint validates that the category exists and is not already marked as deleted.
- Returns a
204 No Contentstatus code if the deletion is successful. - Handles errors appropriately, returning the correct status codes for not found or other issues.
Requirements
- Implement API endpoint for soft deleting a category.
- Validate that the category exists and is not already marked as deleted.
- Handle unexpected errors and return the appropriate status code.
Expected Outcome
- Users should be able to send a request to soft delete a category.
- Users should receive appropriate status codes based on the outcome of the request.
Endpoints
[DELETE] /api/v1/categories/{id}
-
Description: Soft deletes a category by setting its
is_deletedflag toTrue. -
Request Path Parameter:
id: The ID of the category to be deleted.
-
Success Response:
- Status:
204 No Content
- Status:
-
Error Response:
-
Status:
404 Not Found -
Body:
{ "detail": "Category not found." }
-
-
Internal Server Error Response:
-
Status:
500 Internal Server Error -
Body:
{ "error": "Internal server error." }
-
Testing
Test Scenarios
-
Successful Soft Deletion
- Ensure that the endpoint successfully soft deletes a category.
- Verify that the response includes a
204 No Contentstatus code.
-
Not Found Error
- Simulate a request to delete a category that does not exist.
- Verify that the endpoint returns a
404 Not Foundstatus code and an appropriate error message.
-
Internal Server Error
- Simulate an internal server error to raise an exception.
- Verify that the endpoint returns a
500 Internal Server Errorstatus code and an appropriate error message.