Skip to content

Commit

Permalink
Merge pull request #10 from UESTCByteDance/tyh-dev
Browse files Browse the repository at this point in the history
fix: 修复点赞和评论接口
  • Loading branch information
yihengggg authored Aug 14, 2023
2 parents 547a439 + 62683ee commit deb6701
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 46 deletions.
47 changes: 11 additions & 36 deletions controllers/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,6 @@ func (c *CommentController) CommentAction() {
}

// CommentList 视频评论列表
//
// {
// "status_code": 0,
// "status_msg": "string",
// "comment_list": [
// {
// "id": 0,
// "user": {
// "id": 0,
// "name": "string",
// "follow_count": 0,
// "follower_count": 0,
// "is_follow": true,
// "avatar": "string",
// "background_image": "string",
// "signature": "string",
// "total_favorited": "string",
// "work_count": 0,
// "favorite_count": 0
// },
// "content": "string",
// "create_date": "string"
// }
// ]
// }
func (c *CommentController) CommentList() {
// 获取必要参数
tokenString := c.GetString("token") // 用户鉴权token
Expand All @@ -122,16 +97,16 @@ func (c *CommentController) CommentList() {
return
}
// 解析token
user, _ := utils.GetUserFromToken(tokenString)
//if err != nil {
// c.Data["json"] = map[string]interface{}{
// "status_code": 1,
// "status_msg": "获取用户信息失败",
// "video_list": nil,
// }
// c.ServeJSON()
// return
//}
user, err := utils.GetUserFromToken(tokenString)
if err != nil {
c.Data["json"] = map[string]interface{}{
"status_code": 1,
"status_msg": "获取用户信息失败",
"video_list": nil,
}
c.ServeJSON()
return
}
// 查询所有评论
var comments []models.Comment
var commentInfos []object.CommentInfo
Expand All @@ -140,7 +115,7 @@ func (c *CommentController) CommentList() {
userInfo := c.GetUserInfo(user.Id)
commentInfo := object.CommentInfo{
Content: comm.Content,
CreateDate: comm.CreateTime.String(),
CreateDate: comm.CreateTime.Format("2006-01-02 15:04"),
ID: int64(comm.Id),
User: userInfo,
}
Expand Down
20 changes: 10 additions & 10 deletions controllers/favorite.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ func (c *FavoriteController) FavoriteAction() {
}
query.One(&user)
c.o.QueryTable(new(models.Video)).Filter("id", videoId).One(&video)
if video.AuthorId.Id == user.Id {
c.Data["json"] = map[string]interface{}{
"status_code": 1,
"status_msg": "不能给自己点赞",
}
c.ServeJSON()
return
}
//if video.AuthorId.Id == user.Id {
// c.Data["json"] = map[string]interface{}{
// "status_code": 1,
// "status_msg": "不能给自己点赞",
// }
// c.ServeJSON()
// return
//}
// 点赞 or 取消点赞
if actionType == 1 {
// 不能重复点赞
exist := c.o.QueryTable(new(models.Favorite)).Filter("user_id", user.Id).Filter("video_id", videoId).Exist()
if exist {
count, _ := c.o.QueryTable(new(models.Favorite)).Filter("user_id", user.Id).Filter("video_id", videoId).Count()
if count > 0 {
c.Data["json"] = map[string]interface{}{
"status_code": 1,
"status_msg": "不能重复点赞",
Expand Down

0 comments on commit deb6701

Please sign in to comment.