Skip to content

Commit a0674f8

Browse files
committed
修复点赞bug
1 parent 710df59 commit a0674f8

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

controllers/video.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ func (c *VideoController) Feed() {
4444
var isFavorite bool
4545
commentCount, _ := c.o.QueryTable(new(models.Comment)).Filter("video_id", video.Id).Count()
4646
favoriteCount, _ := c.o.QueryTable(new(models.Favorite)).Filter("video_id", video.Id).Count()
47-
if favoriteCount == 0 {
48-
isFavorite = false
47+
//判断当前用户是否点赞该视频
48+
if baseId, err := utils.GetUserIdFromToken(token); err == nil {
49+
if exist := c.o.QueryTable(new(models.Favorite)).Filter("user_id", baseId).Filter("video_id", video.Id).Exist(); exist {
50+
isFavorite = true
51+
} else {
52+
isFavorite = false
53+
}
4954
} else {
50-
isFavorite = true
55+
isFavorite = false
5156
}
5257
userInfo := c.GetUserInfo(video.AuthorId.Id, token)
5358
videoList = append(videoList, &object.VideoInfo{
@@ -140,10 +145,15 @@ func (c *VideoController) List() {
140145
var isFavorite bool
141146
commentCount, _ := c.o.QueryTable(new(models.Comment)).Filter("video_id", video.Id).Count()
142147
favoriteCount, _ := c.o.QueryTable(new(models.Favorite)).Filter("video_id", video.Id).Count()
143-
if favoriteCount == 0 {
144-
isFavorite = false
148+
//判断当前用户是否点赞该视频
149+
if baseId, err := utils.GetUserIdFromToken(token); err == nil {
150+
if exist := c.o.QueryTable(new(models.Favorite)).Filter("user_id", baseId).Filter("video_id", video.Id).Exist(); exist {
151+
isFavorite = true
152+
} else {
153+
isFavorite = false
154+
}
145155
} else {
146-
isFavorite = true
156+
isFavorite = false
147157
}
148158

149159
videoList = append(videoList, &object.VideoInfo{

0 commit comments

Comments
 (0)