...
|
...
|
@@ -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{}
|
|
|
} |
...
|
...
|
|