Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Product Comments Endpoints (Create & Update) #654

Open
9 tasks done
idehen-divine opened this issue Mar 2, 2025 · 0 comments · May be fixed by #655
Open
9 tasks done

Implement Product Comments Endpoints (Create & Update) #654

idehen-divine opened this issue Mar 2, 2025 · 0 comments · May be fixed by #655

Comments

@idehen-divine
Copy link

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.
@idehen-divine idehen-divine changed the title **Implement Product Comments Endpoints (Create & Update)** Implement Product Comments Endpoints (Create & Update) Mar 2, 2025
@idehen-divine idehen-divine linked a pull request Mar 2, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant