-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Description
Description
Implement endpoints to allow users to create and update product comments.
Acceptance Criteria
POST /api/v1/organisations/{orgId}/products/{productId}/comments
- It should be a PROTECTED endpoint requiring authentication.
- It should allow authenticated users to add comments to a product.
- It should validate input and return appropriate error messages if validation fails.
- It should return a success response with the created comment details.
PUT /api/v1/organisations/{productId}/comments/{commentId}
- It should be a PROTECTED endpoint requiring authentication.
- It should allow authenticated users to update their own comments.
- It should return an appropriate error message if the comment does not exist or the user lacks permission.
Purpose
To enable users to leave comments on products and update their own comments when needed.
Requirements
- Develop server-side logic for creating and updating product comments based on the acceptance criteria.
- Ensure proper validation before performing operations.
- Implement authorization to ensure only the comment owner can update it.
- Write unit tests to confirm correctness and accuracy.
Expected Outcome
Users should be able to add and update comments on products while ensuring authorization and validation rules are met.
Tasks
- Create POST endpoint
/api/v1/organisations/{orgId}/products/{productId}/comments
to allow commenting. - Create PUT endpoint
/api/v1/organisations/{productId}/comments/{commentId}
to allow updating a comment. - Validate request data for both endpoints.
- Implement authorization checks for updating comments.
- Write unit tests covering all scenarios.
Example Requests (With Auth Token)
POST Request (Create Comment)
curl -X POST {rootdomain}/api/v1/organisations/{orgId}/products/{productId}/comments \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "comment": "This is a test comment" }'
Response (Success)
{
"status_code": 201,
"message": "Comment added successfully",
"data": { "id": 1, "product_id": 123, "comment": "This is a test comment" }
}
Response (Error - Validation Failure)
{
"status_code": 422,
"message": "Validation failed",
"errors": { "comment": ["The comment field is required."] }
}
PUT Request (Update Comment)
curl -X PUT {rootdomain}/api/v1/organisations/{productId}/comments/{commentId} \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "comment": "Updated comment text" }'
Response (Success)
{
"status_code": 200,
"message": "Comment updated successfully",
"data": { "id": 1, "product_id": 123, "comment": "Updated comment text" }
}
Response (Error - Not Found)
{
"status_code": 404,
"message": "Comment not found."
}
Testing
- Write unit tests for creating and updating product comments.
- Test for successful comment creation and update scenarios.
- Test for unauthorized update attempts.
- Test for validation failures and missing data cases.
Metadata
Metadata
Assignees
Labels
No labels