From a0674f8e8becbc0dda5e12854a04ae67626ed346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8F=A9?= <1939311091@qq.com> Date: Wed, 16 Aug 2023 19:33:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=82=B9=E8=B5=9Ebug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/video.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/controllers/video.go b/controllers/video.go index 194fc1a..acd343a 100644 --- a/controllers/video.go +++ b/controllers/video.go @@ -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{ @@ -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{