正在显示
1 个修改的文件
包含
26 行增加
和
4 行删除
@@ -3,8 +3,10 @@ package article | @@ -3,8 +3,10 @@ package article | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | 5 | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
8 | 10 | ||
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
@@ -16,6 +18,7 @@ type MiniArticleMarkListLogic struct { | @@ -16,6 +18,7 @@ type MiniArticleMarkListLogic struct { | ||
16 | logx.Logger | 18 | logx.Logger |
17 | ctx context.Context | 19 | ctx context.Context |
18 | svcCtx *svc.ServiceContext | 20 | svcCtx *svc.ServiceContext |
21 | + userCache map[int64]*domain.User | ||
19 | } | 22 | } |
20 | 23 | ||
21 | func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleMarkListLogic { | 24 | func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleMarkListLogic { |
@@ -23,6 +26,7 @@ func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext | @@ -23,6 +26,7 @@ func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext | ||
23 | Logger: logx.WithContext(ctx), | 26 | Logger: logx.WithContext(ctx), |
24 | ctx: ctx, | 27 | ctx: ctx, |
25 | svcCtx: svcCtx, | 28 | svcCtx: svcCtx, |
29 | + userCache: make(map[int64]*domain.User, 0), | ||
26 | } | 30 | } |
27 | } | 31 | } |
28 | 32 | ||
@@ -36,10 +40,16 @@ func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMar | @@ -36,10 +40,16 @@ func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMar | ||
36 | if err != nil { | 40 | if err != nil { |
37 | return nil, err | 41 | return nil, err |
38 | } | 42 | } |
43 | + companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, l.svcCtx.DefaultDBConn(), userToken.CompanyId) | ||
44 | + if err != nil { | ||
45 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
46 | + } | ||
39 | resp = &types.MiniArticleMarkListResponse{} | 47 | resp = &types.MiniArticleMarkListResponse{} |
40 | resp.Total = total | 48 | resp.Total = total |
41 | resp.List = make([]types.MiniArticleMarkItem, 0) | 49 | resp.List = make([]types.MiniArticleMarkItem, 0) |
50 | + var author domain.User | ||
42 | for _, item := range list { | 51 | for _, item := range list { |
52 | + author = l.getAuthor(l.svcCtx.DefaultDBConn(), item.Author.Id) | ||
43 | to := types.MiniArticleMarkItem{ | 53 | to := types.MiniArticleMarkItem{ |
44 | Id: item.Id, | 54 | Id: item.Id, |
45 | CompanyId: item.CompanyId, | 55 | CompanyId: item.CompanyId, |
@@ -48,10 +58,10 @@ func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMar | @@ -48,10 +58,10 @@ func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMar | ||
48 | Author: types.SimpleUser{ | 58 | Author: types.SimpleUser{ |
49 | Id: item.Author.Id, | 59 | Id: item.Author.Id, |
50 | CompanyId: item.Author.CompanyId, | 60 | CompanyId: item.Author.CompanyId, |
51 | - CompanyName: item.Author.Company, | ||
52 | - Name: item.Author.Name, | ||
53 | - Avatar: item.Author.Avatar, | ||
54 | - Position: item.Author.Position, | 61 | + CompanyName: companyInfo.Name, |
62 | + Name: author.Name, | ||
63 | + Avatar: author.Avatar, | ||
64 | + Position: author.Position, | ||
55 | }, | 65 | }, |
56 | UpdatedAt: item.UpdatedAt, | 66 | UpdatedAt: item.UpdatedAt, |
57 | } | 67 | } |
@@ -59,3 +69,15 @@ func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMar | @@ -59,3 +69,15 @@ func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMar | ||
59 | } | 69 | } |
60 | return resp, nil | 70 | return resp, nil |
61 | } | 71 | } |
72 | + | ||
73 | +func (l *MiniArticleMarkListLogic) getAuthor(conn transaction.Conn, userid int64) domain.User { | ||
74 | + if u, ok := l.userCache[userid]; ok { | ||
75 | + return *u | ||
76 | + } | ||
77 | + toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid) | ||
78 | + if err == nil { | ||
79 | + l.userCache[toUser.Id] = toUser | ||
80 | + return *toUser | ||
81 | + } | ||
82 | + return domain.User{} | ||
83 | +} |
-
请 注册 或 登录 后发表评论