Appearance
评论模块提供文档和块的评论功能。
/comments
/comments/:commentId
接口: POST /api/v1/comments
POST /api/v1/comments
说明: 创建评论或回复
请求头:
Authorization: Bearer <your-access-token> Content-Type: application/json
请求体:
{ "docId": "doc_1705123456789_xyz456", "blockId": "b_1705123456790_block001", "content": "这是一条评论", "mentions": ["u_1705123456789_abc123"], "parentCommentId": null }
字段说明:
docId
blockId
content
mentions
parentCommentId
响应示例:
{ "success": true, "data": { "commentId": "comment_1705123456789_abc123", "docId": "doc_1705123456789_xyz456", "blockId": "b_1705123456790_block001", "content": "这是一条评论", "mentions": ["u_1705123456789_abc123"], "parentCommentId": null, "createdBy": "u_1705123456789_xyz456", "createdAt": "2024-01-15T10:30:00.000Z" } }
说明:
状态码:
201 Created
400 Bad Request
403 Forbidden
404 Not Found
接口: GET /api/v1/comments
GET /api/v1/comments
说明: 获取文档或块的评论列表
Authorization: Bearer <your-access-token>
查询参数:
page
pageSize
{ "success": true, "data": { "items": [ { "commentId": "comment_1705123456789_abc123", "docId": "doc_1705123456789_xyz456", "blockId": "b_1705123456790_block001", "content": "这是一条评论", "mentions": ["u_1705123456789_abc123"], "parentCommentId": null, "createdBy": "u_1705123456789_xyz456", "createdAt": "2024-01-15T10:30:00.000Z" } ], "total": 1, "page": 1, "pageSize": 20 } }
200 OK
接口: GET /api/v1/comments/:commentId
GET /api/v1/comments/:commentId
说明: 获取评论的详细信息
路径参数:
commentId
接口: PATCH /api/v1/comments/:commentId
PATCH /api/v1/comments/:commentId
说明: 更新评论内容(仅本人可以更新)
{ "content": "更新后的评论内容" }
权限要求: 仅评论创建者可以更新
{ "success": true, "data": { "commentId": "comment_1705123456789_abc123", "content": "更新后的评论内容", "updatedAt": "2024-01-15T12:00:00.000Z" } }
接口: DELETE /api/v1/comments/:commentId
DELETE /api/v1/comments/:commentId
说明: 删除评论(软删除,仅本人可以删除)
权限要求: 仅评论创建者可以删除
{ "success": true, "data": { "message": "评论已删除" } }
// 创建评论 async function createComment(docId: string, content: string) { const response = await fetch('http://localhost:5200/api/v1/comments', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${accessToken}`, }, body: JSON.stringify({ docId, content, }), }); return await response.json(); } // 回复评论 async function replyComment( docId: string, parentCommentId: string, content: string ) { const response = await fetch('http://localhost:5200/api/v1/comments', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${accessToken}`, }, body: JSON.stringify({ docId, parentCommentId, content, }), }); return await response.json(); } // 获取评论列表 async function getComments(docId: string, blockId?: string) { const url = new URL('http://localhost:5200/api/v1/comments'); url.searchParams.set('docId', docId); if (blockId) { url.searchParams.set('blockId', blockId); } const response = await fetch(url.toString(), { headers: { 'Authorization': `Bearer ${accessToken}`, }, }); return await response.json(); }
评论 API
评论模块提供文档和块的评论功能。
接口列表
/comments/comments/comments/:commentId/comments/:commentId/comments/:commentId创建评论
接口:
POST /api/v1/comments说明: 创建评论或回复
请求头:
请求体:
字段说明:
docIdblockIdcontentmentionsparentCommentId响应示例:
说明:
blockId,系统会验证:parentCommentId,系统会验证:状态码:
201 Created- 创建成功400 Bad Request- 请求参数错误(块不属于该文档、块已被删除、父评论不属于该文档)403 Forbidden- 没有权限访问文档404 Not Found- 文档、块或父评论不存在获取评论列表
接口:
GET /api/v1/comments说明: 获取文档或块的评论列表
请求头:
查询参数:
docIdblockIdpagepageSize响应示例:
状态码:
200 OK- 获取成功400 Bad Request- 缺少 docId 参数获取评论详情
接口:
GET /api/v1/comments/:commentId说明: 获取评论的详细信息
请求头:
路径参数:
commentId响应示例:
状态码:
200 OK- 获取成功404 Not Found- 评论不存在403 Forbidden- 没有权限访问更新评论
接口:
PATCH /api/v1/comments/:commentId说明: 更新评论内容(仅本人可以更新)
请求头:
路径参数:
commentId请求体:
字段说明:
content权限要求: 仅评论创建者可以更新
响应示例:
状态码:
200 OK- 更新成功404 Not Found- 评论不存在403 Forbidden- 没有权限(非评论创建者)删除评论
接口:
DELETE /api/v1/comments/:commentId说明: 删除评论(软删除,仅本人可以删除)
请求头:
路径参数:
commentId权限要求: 仅评论创建者可以删除
响应示例:
说明:
状态码:
200 OK- 删除成功404 Not Found- 评论不存在403 Forbidden- 没有权限(非评论创建者)代码示例
JavaScript / TypeScript