Skip to content

Commit

Permalink
修复点赞bug
Browse files Browse the repository at this point in the history
  • Loading branch information
palp1tate committed Aug 16, 2023
1 parent 710df59 commit a0674f8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions controllers/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ func (c *VideoController) Feed() {
var isFavorite bool
commentCount, _ := c.o.QueryTable(new(models.Comment)).Filter("video_id", video.Id).Count()
favoriteCount, _ := c.o.QueryTable(new(models.Favorite)).Filter("video_id", video.Id).Count()
if favoriteCount == 0 {
isFavorite = false
//判断当前用户是否点赞该视频
if baseId, err := utils.GetUserIdFromToken(token); err == nil {
if exist := c.o.QueryTable(new(models.Favorite)).Filter("user_id", baseId).Filter("video_id", video.Id).Exist(); exist {
isFavorite = true
} else {
isFavorite = false
}
} else {
isFavorite = true
isFavorite = false
}
userInfo := c.GetUserInfo(video.AuthorId.Id, token)
videoList = append(videoList, &object.VideoInfo{
Expand Down Expand Up @@ -140,10 +145,15 @@ func (c *VideoController) List() {
var isFavorite bool
commentCount, _ := c.o.QueryTable(new(models.Comment)).Filter("video_id", video.Id).Count()
favoriteCount, _ := c.o.QueryTable(new(models.Favorite)).Filter("video_id", video.Id).Count()
if favoriteCount == 0 {
isFavorite = false
//判断当前用户是否点赞该视频
if baseId, err := utils.GetUserIdFromToken(token); err == nil {
if exist := c.o.QueryTable(new(models.Favorite)).Filter("user_id", baseId).Filter("video_id", video.Id).Exist(); exist {
isFavorite = true
} else {
isFavorite = false
}
} else {
isFavorite = true
isFavorite = false
}

videoList = append(videoList, &object.VideoInfo{
Expand Down

0 comments on commit a0674f8

Please sign in to comment.