@@ -45,12 +45,12 @@ func (s *articleService) BuildArticle(user *model.User, title string, content st
4545 return article , nil
4646}
4747
48- func (s * articleService ) GetArticleList (limit int , cursorTime int64 , sortby string , order string ) (* model.ArticleListResponse , error ) {
48+ func (s * articleService ) GetArticleList (currentUser * model. User , limit int , cursorTime int64 , sortby string , order string ) (* model.ArticleListResponse , error ) {
4949 resp := & model.ArticleListResponse {}
5050 fields := []string {"id" , "title" , "create_time" , "user_id" , "view_count" , "comment_count" , "like_count" , "content" }
5151 articles := repository .ArticleRepository .GetArticleFields (util .DB (), fields , cursorTime , limit , sortby , order )
5252
53- briefList , minCursorTime := buildArticleList (articles )
53+ briefList , minCursorTime := buildArticleList (currentUser , articles )
5454
5555 resp .Cursor = minCursorTime
5656 for i := range briefList {
@@ -63,7 +63,7 @@ func (s *articleService) GetArticleList(limit int, cursorTime int64, sortby stri
6363 return resp , nil
6464}
6565
66- func (s * articleService ) GetArticleByID (id int64 ) (* model.ArticleResponse , error ) {
66+ func (s * articleService ) GetArticleByID (currentUser * model. User , id int64 ) (* model.ArticleResponse , error ) {
6767 articleInfo , err := repository .ArticleRepository .GetArticleByID (util .DB (), id )
6868 if err != nil {
6969 return nil , errors .New ("查询文章信息出错" )
@@ -78,14 +78,15 @@ func (s *articleService) GetArticleByID(id int64) (*model.ArticleResponse, error
7878 Title : articleInfo .Title ,
7979 User : BuildUserBriefInfo (userInfo ),
8080 Content : util .MarkdownToHTML (articleInfo .Content ),
81+ Liked : LCService .JudgeArticleLiked (articleInfo , currentUser ),
8182 CommentCount : articleInfo .CommentCount ,
8283 LikeCount : articleInfo .LikeCount ,
8384 CreateTime : articleInfo .CreateTime ,
8485 }
8586 return resp , nil
8687}
8788
88- func buildArticleList (articles []model.Article ) ([]* model.ArticleBriefInfo , int64 ) {
89+ func buildArticleList (currentUser * model. User , articles []model.Article ) ([]* model.ArticleBriefInfo , int64 ) {
8990 var minCursorTime int64 = model .MAXCursorTime
9091 briefList := make ([]* model.ArticleBriefInfo , len (articles ))
9192 for i := range articles {
@@ -99,8 +100,8 @@ func buildArticleList(articles []model.Article) ([]*model.ArticleBriefInfo, int6
99100 briefList [i ].LikeCount = articles [i ].LikeCount
100101 briefList [i ].ViewCount = articles [i ].ViewCount
101102 briefList [i ].CreateTime = articles [i ].CreateTime
103+ briefList [i ].Liked = LCService .JudgeArticleLiked (& articles [i ], currentUser )
102104 user , _ := repository .UserRepository .GetUserByUserID (util .DB (), articles [i ].UserID )
103- briefList [i ].Liked = LCService .JudgeArticleLiked (& articles [i ], user )
104105 briefList [i ].User = BuildUserBriefInfo (user )
105106 }
106107
0 commit comments