Description
Develop an endpoint to handle requests to create a new category. If the category is created successfully, it will be returned to the client with a 201 Created status. If an error occurs, an appropriate error status will be returned.
Category Table Schema
| Field |
Type |
Description |
Constraints |
| id |
Integer |
Unique identifier for the category |
Primary Key, Auto Increment |
| name |
String |
Name of the category |
Unique, Not Null, Max Length: 255 |
| description |
String |
Description of the category |
Max Length: 500 |
| is_deleted |
Boolean |
Flag for soft deletion of the category |
Default: False |
| created_at |
DateTime |
Timestamp when the category was created |
Default: Current Timestamp |
| updated_at |
DateTime |
Timestamp when the category was last updated |
Default: Current Timestamp, Updated on Modification |
Acceptance Criteria
- The endpoint allows creating a new category with the fields: name and description.
- The endpoint validates the input data and returns appropriate error messages for invalid data or missing required fields.
- Returns a
201 Created status code and the created category data when the category is created successfully.
Requirements
Expected Outcome
- Users should be able to send a request to create a new category.
- Users should receive appropriate status codes and responses based on the outcome of the request.
Endpoints
[POST] /api/v1/categories
Testing
Test Scenarios
-
Successful Creation of Category
- Ensure that the endpoint successfully creates a new category.
- Verify that the response includes the created category data and a
201 Created status code.
-
Conflict Error
- Simulate a request to create a category with a name that already exists.
- Verify that the endpoint returns a
409 Conflict status 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 Error status code and an appropriate error message.
-
Invalid Data
- Send requests with invalid data (e.g., missing required fields, incorrect data types).
- Verify that the endpoint returns a
422 Unprocessable Entity status code and an appropriate error message.
-
Boundary Testing for Fields
- Test the maximum length constraints for the name and description fields.
- Ensure that the endpoint handles the boundary conditions correctly and returns appropriate error messages for exceeding the length limits.
Description
Develop an endpoint to handle requests to create a new category. If the category is created successfully, it will be returned to the client with a
201 Createdstatus. If an error occurs, an appropriate error status will be returned.Category Table Schema
Acceptance Criteria
201 Createdstatus code and the created category data when the category is created successfully.Requirements
409 Conflictstatus code.Expected Outcome
Endpoints
[POST] /api/v1/categoriesDescription: Creates a new category.
Request Body (JSON):
{ "name": "Technology", "description": "Posts related to technology and gadgets." }Success Response:
Status:
201 CreatedBody:
{ "id": 1, "name": "Technology", "description": "Posts related to technology and gadgets.", "created_at": "2024-07-18T00:00:00Z", "updated_at": "2024-07-18T00:00:00Z" }Error Response:
Status:
500 Internal Server ErrorBody:
{ "error": "Internal server error." }Conflict Response:
Status:
409 ConflictBody:
{ "detail": "A category with this name already exists." }Validation Error Response:
Status:
422 Unprocessable EntityBody:
{ "detail": "Invalid data message." }Testing
Test Scenarios
Successful Creation of Category
201 Createdstatus code.Conflict Error
409 Conflictstatus code and an appropriate error message.Internal Server Error
500 Internal Server Errorstatus code and an appropriate error message.Invalid Data
422 Unprocessable Entitystatus code and an appropriate error message.Boundary Testing for Fields