API Calls

  • Fetch paginated comments: fetchPaginatedComments
  • Fetch total comment count: fetchTotalComments
  • Search comments: searchComments
  • Delete a comment: deleteComment
  • Delete multiple comments: deleteManyComments

API Documentation

1. Get Paginated Comments

Endpoint: /admin/comments Method: GET Description: Retrieves a paginated list of comments with filtering and sorting options. Request Parameters:

{
  "page": 1,
  "limit": 10,
  "search": "keyword",
  "likesFilter": "10",
  "sort": "desc"
}

Response:

{
  "comments": [
    {
      "_id": "abc123",
      "comment": "This is a sample comment.",
      "commented_by": {
        "username": "user123",
        "fullname": "John Doe",
        "profile_img": "image_url"
      },
      "blog_id": {
        "title": "Sample Blog Title",
        "blog_id": "xyz789"
      },
      "commentedAt": "2024-02-01T10:00:00Z",
      "likes": {
        "total": 5
      }
    }
  ],
  "total": 100,
  "page": 1,
  "totalPages": 10
}

2. Get Total Comment Count

Endpoint: /admin/comments/count Method: GET Description: Retrieves the total count of all comments on the platform. Response:

{
  "total": 1000
}

3. Search Comments

Endpoint: /admin/comments Method: GET Description: Searches comments by content. Request Parameters:

{
  "search": "important feedback"
}

Response:

{
  "comments": [...],
  "total": 50
}

4. Delete a Comment

Endpoint: /admin/comments/{id} Method: DELETE Description: Deletes a single comment by its ID. Response:

{
  "message": "Comment deleted successfully"
}

5. Delete Multiple Comments

Endpoint: /admin/comments/deleteMany Method: POST Description: Deletes multiple comments by their IDs. Request Body:

{
  "ids": ["abc123", "xyz789"]
}

Response:

{
  "message": "Deleted 2 comments (including nested replies)"
}

Usage Flow

  1. The admin accesses the Comments Management page.
  2. The component fetches paginated comment data from /admin/comments.
  3. The admin can search for comments by entering a query.
  4. The admin can delete a single comment by clicking the delete button, triggering a request to /admin/comments/{id}.
  5. The admin can bulk delete comments by selecting multiple entries and triggering /admin/comments/deleteMany.
  6. A toast notification confirms success or failure of deletion.

Error Handling

  • Invalid comment ID: Returns 404 Not Found
  • Unauthorized request: Returns 403 Forbidden
  • Server errors: Returns 500 Internal Server Error

Conclusion

The Comments Management panel ensures effective moderation of user comments, providing administrators with tools to filter, delete, and search through discussions on blog posts. The API endpoints facilitate seamless integration and control over comment operations.