1
This commit is contained in:
parent
af6c39f5f0
commit
c44a1e565b
@ -92,12 +92,22 @@ func (r *Article) GetArticle(c *gin.Context) {
|
||||
|
||||
// 获取数据
|
||||
articleDao := dao.ArticleDao{}
|
||||
article, err := articleDao.GetArticlePreloadById(articleId)
|
||||
article, err := articleDao.GetArticleById(articleId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("文章错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取文章作者
|
||||
articleAuthorDao := dao.ArticleAuthorDao{}
|
||||
articleAuthors, err := articleAuthorDao.GetArticleAuthorListPreloadByAuthorId(articleId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("文章错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
article.ArticleAuthor = articleAuthors
|
||||
|
||||
// 获取排名
|
||||
rank, _ := articleDao.GetArticleRank(article.ArticleId)
|
||||
|
||||
|
||||
@ -92,12 +92,22 @@ func (r *Video) GetVideo(c *gin.Context) {
|
||||
|
||||
// 获取数据
|
||||
videoDao := dao.VideoDao{}
|
||||
video, err := videoDao.GetVideoPreloadById(videoId)
|
||||
video, err := videoDao.GetVideoById(videoId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("文章错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取视频作者
|
||||
videoAuthorDao := dao.VideoAuthorDao{}
|
||||
videoAuthors, err := videoAuthorDao.GetVideoAuthorListPreloadByVideoId(videoId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("文章错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
video.VideoAuthor = videoAuthors
|
||||
|
||||
// 获取排名
|
||||
rank, _ := videoDao.GetVideoRank(video.VideoId)
|
||||
|
||||
|
||||
@ -28,6 +28,15 @@ func (r *ArticleAuthorDao) GetArticleAuthorPreloadById(AuthorId int64) (m *model
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleAuthorListPreloadByAuthorId 获取数据-列表-文章id
|
||||
func (r *ArticleAuthorDao) GetArticleAuthorListPreloadByAuthorId(articleId int64) (m []*model.ArticleAuthor, err error) {
|
||||
err = global.Db.Preload(clause.Associations).Where("article_id = ?", articleId).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteArticleAuthor 删除
|
||||
func (r *ArticleAuthorDao) DeleteArticleAuthor(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.ArticleAuthor{}).Error
|
||||
|
||||
@ -28,6 +28,15 @@ func (r *VideoAuthorDao) GetVideoAuthorPreloadById(authorId int64) (m *model.Vid
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoAuthorListPreloadByVideoId 获取数据-列表-视频id
|
||||
func (r *VideoAuthorDao) GetVideoAuthorListPreloadByVideoId(videoId int64) (m []*model.VideoAuthor, err error) {
|
||||
err = global.Db.Preload(clause.Associations).Where("video_id = ?", videoId).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteVideoAuthor 删除
|
||||
func (r *VideoAuthorDao) DeleteVideoAuthor(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.VideoAuthor{}).Error
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user