Skip to content

Category Delete API Endpoint #9

@Pythonian

Description

@Pythonian

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_deleted flag to True.
  • The endpoint validates that the category exists and is not already marked as deleted.
  • Returns a 204 No Content status 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_deleted flag to True.

  • Request Path Parameter:

    • id: The ID of the category to be deleted.
  • Success Response:

    • Status: 204 No Content
  • 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

  1. Successful Soft Deletion

    • Ensure that the endpoint successfully soft deletes a category.
    • Verify that the response includes a 204 No Content status code.
  2. Not Found Error

    • Simulate a request to delete a category that does not exist.
    • Verify that the endpoint returns a 404 Not Found status code and an appropriate error message.
  3. Internal Server Error

    • Simulate an internal server error to raise an exception.
    • Verify that the endpoint returns a 500 Internal Server Error status code and an appropriate error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions