作者 tangxvhui

调整 文章搜索结果中作者展示的数据

... ... @@ -544,6 +544,7 @@ type (
MiniSearchArticleItem{
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
AuthorId int64 `json:"authorId"`
Author string `json:"author"` // 发布人
Avatar string `json:"avatar"`// 发布人的头像
Images []string `json:"images"`
... ...
... ... @@ -5,6 +5,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
... ... @@ -13,8 +14,9 @@ import (
type MiniSearchArticlePageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
svcCtx *svc.ServiceContext
userCache map[int64]*domain.User
}
func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic {
... ... @@ -63,11 +65,13 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
}
for i, val := range articleList {
author := l.getAuthor(conn, val.AuthorId)
item := types.MiniSearchArticleItem{
ArticleId: val.Id,
Title: val.Title,
Author: val.Author.Name,
Avatar: val.Author.Avatar,
AuthorId: val.AuthorId,
Author: author.Name,
Avatar: author.Avatar,
Images: []string{},
CreatedAt: val.CreatedAt,
MeReadFlag: 0,
... ... @@ -84,3 +88,15 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
return resp, nil
}
func (l *MiniSearchArticlePageLogic) getAuthor(conn transaction.Conn, userid int64) domain.User {
if u, ok := l.userCache[userid]; ok {
return *u
}
toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
if err == nil {
l.userCache[toUser.Id] = toUser
return *toUser
}
return domain.User{}
}
... ...
... ... @@ -1315,6 +1315,7 @@ type MiniSearchArticleResponse struct {
type MiniSearchArticleItem struct {
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
AuthorId int64 `json:"authorId"`
Author string `json:"author"` // 发布人
Avatar string `json:"avatar"` // 发布人的头像
Images []string `json:"images"`
... ...