🎨 修改文章获取接口

This commit is contained in:
loser 2023-12-11 18:56:34 +08:00
parent 28055e99c9
commit cb7bce5cef

View File

@ -36,11 +36,14 @@ func (a ArticleService) GetArticleById(id, userId string) (article *common.Artic
err = global.GVA_DB.Where("id = ?", id).First(&article).Error err = global.GVA_DB.Where("id = ?", id).First(&article).Error
err = global.GVA_DB.Table("articles").Where("id = ?", id).Update("reading_num", gorm.Expr("reading_num + ?", 1)).Error err = global.GVA_DB.Table("articles").Where("id = ?", id).Update("reading_num", gorm.Expr("reading_num + ?", 1)).Error
// 判断是否收藏 if userId != "" {
var favorite app.Favorite // 判断是否收藏
err = global.GVA_DB.Where("wz_id = ? AND user_id = ?", id, userId).First(&favorite).Error var favorite app.Favorite
if favorite.ID != 0 { global.GVA_DB.Where("wz_id = ? AND user_id = ?", id, userId).First(&favorite)
article.IsFavorite = 1 if favorite.ID != 0 {
article.IsFavorite = 1
}
} }
return return
} }