作者 庄敏学

文章列表bug

... ... @@ -389,12 +389,12 @@ type (
SystemArticleSearch {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"author"` //发布人ID
AuthorId int64 `json:"authorId"` //发布人ID
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
CountComment int `json:"countComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
... ...
... ... @@ -43,15 +43,26 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
}
authorIds := make([]int64, 0)
lo.ForEach(articles, func(item *domain.Article, index int) {
authorIds = append(authorIds, item.AuthorId)
})
//查询用户数据,重新赋值更新用户名称
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
lo.ForEach(articles, func(item *domain.Article, index int) {
images := make([]string, 0)
lo.ForEach(item.Images, func(img domain.Image, n int) {
images = append(images, img.Url)
})
author := item.Author.Name
for _, user := range users {
if user.Id == item.AuthorId {
author = user.Name
}
}
resp.List = append(resp.List, types.SystemArticleSearch{
Id: item.Id,
Title: item.Title,
AuthorId: item.AuthorId,
Author: item.Author.Name,
Author: author,
Images: images,
CreatedAt: item.CreatedAt,
CountLove: item.CountLove,
... ... @@ -60,16 +71,6 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
Tags: nil,
TargetUser: int(item.TargetUser),
})
authorIds = append(authorIds, item.AuthorId)
})
//查询用户数据,重新赋值更新用户名称
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
lo.ForEach(resp.List, func(item types.SystemArticleSearch, index int) {
for _, user := range users {
if user.Id == item.AuthorId {
resp.List[index].Author = user.Name
}
}
})
return resp, nil
return
}
... ...
... ... @@ -1172,12 +1172,12 @@ type SystemArticleSearchResponse struct {
type SystemArticleSearch struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"author"` //发布人ID
AuthorId int64 `json:"authorId"` //发布人ID
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
CountComment int `json:"countComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
... ...