File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments