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

[FEAT]: Implement an endpoint to get all comment on a blog post #224

Open
15 tasks
dhamolahedonist opened this issue Jul 24, 2024 · 1 comment
Open
15 tasks
Labels

Comments

@dhamolahedonist
Copy link
Contributor

dhamolahedonist commented Jul 24, 2024

Description:

Implement an endpoint to retrieve all comments on a specific blog post. This feature should ensure that users can fetch all comments associated with a particular blog post.

Acceptance Criteria:

API Endpoint Implementation:

  • The endpoint should be accessible at /api/v1/blogs/:blog-id/comments.
  • The endpoint should handle GET requests.

Authorization:

  • Ensure that only authenticated users can access the endpoint.
  • Validate the token received in the request to authenticate the user.

Data Handling:

  • On successful request, fetch all comments associated with the specified blog post from the database.
  • Each comment should include relevant details such as the commenter's name, the comment text, and the timestamp.

Response:

  • On success: The API should return a 200 OK status code with the list of comments.
  • On failure: The API should return appropriate status codes and messages for different error scenarios (e.g., blog post not found, unauthorized access).

Request Example:

GET /api/v1/blogs/123/comments
Authorization: Bearer <jwt_token>

Successful Response Example:

{
  "message": "Comments retrieved successfully",
  "status": 200,
  "comments": [
    {
      "id": 1,
      "author": "Jane Doe",
      "text": "Great post!",
      "timestamp": "2024-07-24T10:00:00Z"
    },
    {
      "id": 2,
      "author": "John Smith",
      "text": "Very informative.",
      "timestamp": "2024-07-24T11:00:00Z"
    }
  ]
}

Error Response Example:

{
  "message": "Unauthorized",
  "status": 401
}

or

{
  "message": "Blog post not found",
  "status": 404
}

or

{
  "message": "Internal server error",
  "status": 500
}

Purpose:

Enable users to retrieve all comments on a specific blog post, providing a way to view discussions and feedback associated with the post.

Requirements:

  • Develop server-side logic to handle the retrieval of comments for a blog post.
  • Implement authorization checks to validate the user's JWT token.
  • Ensure comments are properly fetched and returned in the response.

Expected Outcome:

  • Users can fetch all comments on a specific blog post, with each comment's details being returned in the response.

Status Codes:

200: Comments retrieved successfully,
401: Unauthorized access due to invalid token,
404: Blog post not found,
500: Internal server error,

Testing:

  • Write unit tests to verify that the endpoint correctly retrieves comments for a blog post.
  • Test authorization to ensure only authenticated users can access the endpoint.
  • Perform integration testing to confirm that comments are correctly fetched and returned in the response.
@PreciousIfeaka
Copy link
Contributor

The request params should be in kebab case and the acceptance criteria should be checklists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants