# Comments（评论管理）

## **GET /api/Comments/{postid}**

* **描述**: 获取指定帖子的评论。
* **参数**:
  * `postid` (string, required): 帖子ID
* **响应**: 200 OK

请求示例

```
//api/Comments/:postid
```

示例代码

```javascript
const myHeaders = new Headers();
myHeaders.append("Authorization", "<API Key>");

const requestOptions = {
  method: "GET",
  headers: myHeaders,
  redirect: "follow"
};

fetch("//api/Comments/:postid", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

返回示例

```json
{
  "success": true,
  "comments": [
    {
      "id": 321,
      "nickname": "admin imarket",
      "username": "admin",
      "userAvatar": "test",
      "content": "这是第一个评论",
      "isLike": false,
      "likeNum": 0,
      "createdAt": "2025-01-22T16:58:20"
    }
  ]
}
```

***

## **POST /api/Comments/Create**

* **描述**: 发表评论。
* **请求体**:
  * `application/json`: `CommentPostRequest` 对象
  * `text/json`: `CommentPostRequest` 对象
  * `application/*+json`: `CommentPostRequest` 对象
* **响应**: 200 OK

请求示例

```json
{
  "content": "<string>",
  "postId": "<ulong>"
}
```

示例代码

```javascript
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "<API Key>");

const raw = JSON.stringify({
  "content": "<string>",
  "postId": "<ulong>"
});

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: raw,
  redirect: "follow"
};

fetch("//api/Comments/Create", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

返回示例

```json
{
  "success": true,
  "commentId": 12
}
```

***

## **GET /api/Comments/Delete**

* **描述**: 删除评论。
* **参数**:
  * `commentId` (string, required): 评论ID
* **响应**: 200 OK

请求示例

```
//api/Comments/Delete?commentId=<ulong>
```

示例代码

```javascript
const myHeaders = new Headers();
myHeaders.append("Authorization", "<API Key>");

const requestOptions = {
  method: "GET",
  headers: myHeaders,
  redirect: "follow"
};

fetch("//api/Comments/Delete?commentId=<string>", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

返回示例

```json
{
  "success": true
}
```

***

## **GET /api/Comments/Like**

* **描述**: 点赞评论。
* **参数**:
  * `commentId` (string, required): 评论ID
* **响应**: 200 OK

请求示例

```
//api/Comments/Like?commentId=<ulong>
```

示例代码

```javascript
const myHeaders = new Headers();
myHeaders.append("Authorization", "<API Key>");

const requestOptions = {
  method: "GET",
  headers: myHeaders,
  redirect: "follow"
};

fetch("//api/Comments/Like?commentId=<string>", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

返回示例

```json
{
  "success": true
}
```

***

## **GET /api/Comments/UnLike**

* **描述**: 取消点赞评论。
* **参数**:
  * `commentId` (string, required): 评论ID
* **响应**: 200 OK

请求示例

```
//api/Comments/UnLike?commentId=<ulong>
```

示例代码

```javascript
const myHeaders = new Headers();
myHeaders.append("Authorization", "<API Key>");

const requestOptions = {
  method: "GET",
  headers: myHeaders,
  redirect: "follow"
};

fetch("//api/Comments/UnLike?commentId=<ulong>", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

返回示例

```json
{
  "success": true
}
```
