Skip to content

Commit

Permalink
feat: 新增点赞/取消点赞评论
Browse files Browse the repository at this point in the history
  • Loading branch information
ultrazg committed Jul 29, 2024
1 parent 4c86b16 commit 1a3e26c
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [收藏评论](/commentCollectCreate)
* [取消已收藏评论](/commentCollectRemove)
* [查询已收藏评论](/commentCollectList)
* [点赞/取消点赞评论](/commentLikeUpdate)
* [首页榜单、精选节目、推荐等](/discovery)
* [首页-刷新「大家都在听」推荐](/refreshEpisodeRecommend)
* [正在收听的人数](/episodeLiveCount)
Expand Down
56 changes: 56 additions & 0 deletions docs/commentLikeUpdate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
### 点赞/取消点赞评论

点赞或取消点赞评论

#### 请求地址

> /comment_like_update
#### 请求方式

> POST
#### 支持格式

> JSON
#### 请求头

| 参数 | 必填 | 类型 | 说明 |
| :------------------ | :--- | :----- | ------------------- |
| x-jike-access-token | true | string | x-jike-access-token |

#### 请求参数

| 参数 | 必填 | 类型 | 说明 |
| :---- | :--- | :------ | ----------------------------------------- |
| id | true | string | 评论 id |
| liked | true | boolean | **true** 为点赞,**false****取消点赞** |

#### 返回字段



#### 示例

> 地址:https://www.example.com/comment_like_update
参数

```javascript
{
"id": "66229567e14d49b402c9e7de",
"liked": true
}
```

响应

```javascript
{
"code": 200,
"data": {},
"msg": "OK"
}
```
2 changes: 1 addition & 1 deletion docs/topList.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

```javascript
{
"cateory": "HOT",
"category": "HOT",
}
```

Expand Down
77 changes: 77 additions & 0 deletions handlers/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,80 @@ var CommentCollectList = func(ctx *gin.Context) {

utils.ReturnJson(response, ctx)
}

type CommentLikeUpdateBody struct {
Liked bool `form:"liked"`
Id string `form:"id"`
}

// CommentLikeUpdate 点赞/取消点赞评论
var CommentLikeUpdate = func(ctx *gin.Context) {
var params *CommentLikeUpdateBody

err := ctx.ShouldBind(&params)
if err != nil {
utils.ReturnBadRequest(ctx, err)

return
}

if params.Id == "" {
utils.ReturnBadRequest(ctx, nil)

return
}

h := ctx.Request.Header
XJikeAccessToken := h.Get("x-jike-access-token")
p := map[string]any{
"liked": params.Liked,
"target": map[string]string{
"id": params.Id,
"type": "COMMENT",
},
"sourcePageName": 15,
"currentPageName": 20,
}
now := time.Now()
isoTime := now.Format("2006-01-02T15:04:05Z07:00")
url := constant.BaseUrl + "/v1/like/update"
headers := map[string]string{
"Host": "api.xiaoyuzhoufm.com",
"User-Agent": "Xiaoyuzhou/2.57.1 (build:1576; iOS 17.4.1)",
"Market": "AppStore",
"App-BuildNo": "1576",
"OS": "ios",
"x-jike-access-token": XJikeAccessToken,
"Manufacturer": "Apple",
"BundleID": "app.podcast.cosmos",
"Connection": "keep-alive",
"abtest-info": "{\"old_user_discovery_feed\":\"enable\"}",
"Accept-Language": "zh-Hant-HK;q=1.0, zh-Hans-CN;q=0.9",
"X-Online-Host": "api.xiaoyuzhoufm.com",
"Model": "iPhone14,2",
"app-permissions": "4",
"Accept": "*/*",
"Content-Type": "application/json",
"App-Version": "2.57.1",
"WifiConnected": "true",
"OS-Version": "17.4.1",
"x-custom-xiaoyuzhou-app-dev": "",
"Local-Time": isoTime,
"Timezone": "Asia/Shanghai",
}

response, code, err := utils.Request(url, http.MethodPost, p, headers)
if err != nil {
ctx.JSON(code, gin.H{
"code": code,
"msg": utils.GetMsg(code),
"data": err.Error(),
})

log.Println("/v1/like/update", code, utils.GetMsg(code))

return
}

utils.ReturnJson(response, ctx)
}
1 change: 1 addition & 0 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func RegisterRouters(engine *gin.Engine) {
engine.POST("/comment_collect_create", utils.CheckAccessToken(), handlers.CreateCommentCollect) // 收藏评论
engine.POST("/comment_collect_remove", utils.CheckAccessToken(), handlers.RemoveCommentCollect) // 取消收藏评论
engine.POST("/comment_collect_list", utils.CheckAccessToken(), handlers.CommentCollectList) // 获取收藏评论列表
engine.POST("/comment_like_update", utils.CheckAccessToken(), handlers.CommentLikeUpdate) // 点赞/取消点赞评论
engine.POST("/discovery", utils.CheckAccessToken(), handlers.Discovery) // 首页榜单、精选节目、推荐等
engine.POST("/refresh_episode_recommend", utils.CheckAccessToken(), handlers.RefreshEpisodeRecommend) // 首页大家都在听-刷新推荐
engine.POST("/episode_live_count", utils.CheckAccessToken(), handlers.Live) // 正在收听的人数
Expand Down

0 comments on commit 1a3e26c

Please sign in to comment.