作者: 蒲锐
日期: 2023-09-019
简介
本文档介绍了评论接口的使用和实现。评论接口是用于在Java应用程序中添加和获取用户评论的接口。通过本接口,开发人员可以轻松地将评论功能集成到他们的应用程序中,以增加用户互动和反馈。
概述
该功能采取主题式评论设计两个数据库表tb_comment以及tb_comment_children,tb_comment存储主评论,tb_comment_children存储子评论,抛弃了以往的树形结构,主题式评论只需在子评论的表上保存回复人和回复目标,极大较少了数据库资源的消耗,以及提高了查询的效率。主评论下只需显示谁回复谁的评论内容,即可实现一个评论数据的分页显示。
数据库表
-
tb_comment
-
tb_comment_children
title: Eggor v1.0.0 language_tabs: - shell: Shell - http: HTTP - javascript: JavaScript - ruby: Ruby - python: Python - php: PHP - java: Java - go: Go toc_footers: [] includes: [] search: true code_clipboard: true highlight_theme: darkula headingLevel: 2 generator: "@tarslib/widdershins v4.0.17"
用户端接口/评论
GET 获取评论以及子评论接口
简介:获取主评论的分页数据,并且每一个主评论下有改id对应的子评论的5条数据,如需查看更多改主评论下的子评论,可在前端点击展开查看更多子评论数据。
GET /eggor/comment/all
请求参数
名称 | 位置 | 类型 | 必选 | 说明 |
type | query | string | 否 | 主评论默认内型为1 |
targetId | query | string | 否 | 帖子的id |
返回示例
200 Response
```json{ "total": 1, "rows": [ { "createBy": null, "createTime": "2023-09-19 15:46:18", "updateBy": null, "updateTime": null, "remark": null, "id": "1687008525917487356", "user": { "userId": 1036, "nickName": "Ania", "sex": "1", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/14/20230914093432A003.jpg" }, "content": { "ops": [ { "insert": { "video": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919074604A010.mp4" } }, { "insert": "评论区也吃安利!!\n" } ] }, "type": 1, "targetId": 242, "replyNum": 0, "likedNum": 0, "children": [ { "id": "1687008525917487326", "fromId": "1036", "toId": "1036", "content": { "ops": [ { "insert": "我是帖子评论的评论的评论,套娃哈哈,也吃安利!\n" }, { "insert": { "video": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919074948A012.mp4" } }, { "insert": "\n" } ] }, "type": 5, "targetId": "1687008525917487356", "createTime": "2023-09-19T15:49:52.000+08:00", "fromUser": { "userId": 1036, "nickName": "Ania", "sex": "1", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/14/20230914093432A003.jpg" }, "toUser": { "userId": 1036, "nickName": "Ania", "sex": "1", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/14/20230914093432A003.jpg" } }, { "id": "1687008525917487325", "fromId": "1036", "toId": null, "content": { "ops": [ { "insert": { "video": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919074733A011.mp4" } }, { "insert": "评论的评论也吃!!!哈哈哈\n" } ] }, "type": 4, "targetId": "1687008525917487356", "createTime": "2023-09-19T15:47:55.000+08:00", "fromUser": { "userId": 1036, "nickName": "Ania", "sex": "1", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/14/20230914093432A003.jpg" }, "toUser": null } ], "isLike": null, "comments": [] } ], "code": 200, "msg": "查询成功" }
返回结果
状态码 | 状态码含义 | 说明 | 数据模型 |
200 | OK | 成功 | Inline |
GET 获取子评论
简介:获取子评论的分页数据,当前端点击展开后,根据对应的主评论id查询更多子评论的分页数据。
GET /eggor/comment/children
获取字评论
请求参数
名称 | 位置 | 类型 | 必选 | 说明 |
Authorization | cookie | string | 否 | none |
type | query | string | 否 | none |
targetId | query | string | 否 | none |
返回示例
200 Response
```json
{ "total": 5, "rows": [ { "id": "1687008525917487330", "fromId": "104", "toId": null, "content": { "ops": [ { "insert": "awefawefawef\nawefaw\nef\naw\ne" }, { "insert": { "mention": { "id": "1", "index": "0", "value": "awefawe", "denotationChar": "#" } } }, { "insert": " \n" } ] }, "type": 4, "targetId": "1687008525917487351", "createTime": "2023-09-19T16:29:37.000+08:00", "fromUser": { "userId": 104, "nickName": "Cyenoch", "sex": "0", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919104507A006.png" }, "toUser": null }, { "id": "1687008525917487324", "fromId": "104", "toId": null, "content": { "ops": [ { "insert": { "video": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919152603A005.mp4" } }, { "insert": "123\n" } ] }, "type": 4, "targetId": "1687008525917487351", "createTime": "2023-09-19T15:28:40.000+08:00", "fromUser": { "userId": 104, "nickName": "Cyenoch", "sex": "0", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919104507A006.png" }, "toUser": null }, { "id": "1687008525917487323", "fromId": "104", "toId": "104", "content": { "ops": [ { "insert": { "video": true } }, { "insert": "12313\n" } ] }, "type": 5, "targetId": "1687008525917487351", "createTime": "2023-09-19T15:19:39.000+08:00", "fromUser": { "userId": 104, "nickName": "Cyenoch", "sex": "0", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919104507A006.png" }, "toUser": { "userId": 104, "nickName": "Cyenoch", "sex": "0", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919104507A006.png" } }, { "id": "1687008525917487322", "fromId": "104", "toId": "104", "content": { "ops": [ { "insert": { "audio": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919151752A003.mp3" } }, { "insert": "a\n" } ] }, "type": 5, "targetId": "1687008525917487351", "createTime": "2023-09-19T15:17:58.000+08:00", "fromUser": { "userId": 104, "nickName": "Cyenoch", "sex": "0", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919104507A006.png" }, "toUser": { "userId": 104, "nickName": "Cyenoch", "sex": "0", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919104507A006.png" } }, { "id": "1687008525917487315", "fromId": "104", "toId": null, "content": { "ops": [ { "insert": "2\n" } ] }, "type": 4, "targetId": "1687008525917487351", "createTime": "2023-09-19T09:44:12.000+08:00", "fromUser": { "userId": 104, "nickName": "Cyenoch", "sex": "0", "avatar": "https://static.testnet.eggor.io/eggor/2023/09/19/20230919104507A006.png" }, "toUser": null } ], "code": 200, "msg": "查询成功" }
返回结果
状态码 | 状态码含义 | 说明 | 数据模型 |
200 | OK | 成功 | Inline |
返回数据结构
POST 添加子评论
简介:添加子评论需要提供type这一参数去判断3种情况:1.评论帖子,4,主评论,5.回复子评论,三种回复目标不同,传递的参数以及保存的数据都将不同,type为1时,直接在帖子下评论,保存的数据在tb_comment表下成为主评论,type为4时,回复的目标是主评论人,数据保存在tb_comment_children中,由于回复目标是主评论人,不需要保存回复人信息,type为5是则是我们常常在bilibili或者微博这些网站看到的评论有回复对象,对象则是子评论的信息。这样就形成了主评论下A回复给B内容的样式。
POST /eggor/comment/add
添加评论的接口
Body 请求参数
```json
{ "content": { "ops": [ { "insert": "主评论" } ] }, "type": 4, "targetId": "1687008525917487311" }
请求参数
名称 | 位置 | 类型 | 必选 | 说明 |
Authorization | header | string | 否 | none |
body | body | object | 否 | none |
返回示例
200 Response
```json
{ "msg": "操作成功", "code": 200 }
返回结果
状态码 | 状态码含义 | 说明 | 数据模型 |
200 | OK | 成功 | Inline |