Skip to content

FEAT: Endpoint to Implement Edit or Update of Comments #1237

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

BlessOnyi
Copy link

[FEAT]: Endpoint to Implement Edit or Update of Comments #1046

Description

This PR implements an endpoint that allows authenticated users to update their comments.

Acceptance Criteria

  • PATCH /api/v1/comments/{id}
  • The endpoint should be protected, requiring authentication.
  • Users should be able to edit only their own comments.
  • It should return an appropriate success message upon successful update.
  • It should return an error message if:
    • The comment does not exist.
    • The user lacks permission to edit it.

Purpose

To allow users to update their own comments while ensuring proper access control and security.

Requirements

  • Develop server-side logic to edit an existing comment based on the given criteria.
  • Validate the comment ID before performing any operation.
  • Implement authorization to ensure only the comment owner can edit it.
  • Write unit tests to confirm correctness and accuracy.

Expected Outcome

  • Users should be able to successfully update their own comments.
  • Unauthorized updates should be prevented.

Tasks

  • Create a PATCH endpoint /api/v1/comments/{id} to edit a comment.
  • Validate the comment ID and ensure it exists before performing the update.
  • Implement authentication and authorization checks.
  • Write unit tests covering success and failure scenarios.

Example Requests [With Auth Token]

PATCH Request:
curl -X PATCH {rootdomain}/api/v1/comments/{id} \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{ "content": "Updated comment text" }'

Response (Success):

{
  "status_code": 200,
  "message": "Comment updated successfully",
  "comment_id": "123",
  "new_content": "Updated comment text"
}

postman-screenshot

Response (
Error - Comment Not Found):

{
  "status_code": 404,
  "message": "Comment not found."
}

Response (Error - Forbidden: No Permission to Edit):

{
  "status_code": 403,
  "message": "You do not have permission to edit this comment."
}

Response (Error - Unauthorized Access: Missing or Invalid Token):

{
  "status_code": 401,
  "message": "Not authorized."
}

Testing

  • Write unit tests to ensure users can edit their comments.
  • Test authentication and authorization checks.
  • Validate error handling for invalid comment IDs and unauthorized updates.

Description

Related Issue (Link to issue ticket)

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate - Postman, etc):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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 this pull request may close these issues.

1 participant