> ## Documentation Index
> Fetch the complete documentation index at: https://docwrite.jooj.us/llms.txt
> Use this file to discover all available pages before exploring further.

# API Blog Comments 

> This section provides details on managing blog comments, allowing administrators to moderate, filter, and delete comments effectively. Comments help engage users in discussions and provide feedback on blog posts.

### 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:**

```json theme={null}
{
  "page": 1,
  "limit": 10,
  "search": "keyword",
  "likesFilter": "10",
  "sort": "desc"
}
```

**Response:**

```json theme={null}
{
  "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:**

```json theme={null}
{
  "total": 1000
}
```

### 3. Search Comments

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

```json theme={null}
{
  "search": "important feedback"
}
```

**Response:**

```json theme={null}
{
  "comments": [...],
  "total": 50
}
```

### 4. Delete a Comment

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

```json theme={null}
{
  "message": "Comment deleted successfully"
}
```

### 5. Delete Multiple Comments

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

```json theme={null}
{
  "ids": ["abc123", "xyz789"]
}
```

**Response:**

```json theme={null}
{
  "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.
