作者 郑周

1 点赞 人 增加公司名称

... ... @@ -45,30 +45,35 @@ func (l *MiniMyBeLikedLogic) MiniMyBeLiked(req *types.MiniBeLikedRequest) (resp
return resp, nil
}
var companyMap = make(map[int64]*domain.Company)
var userMap = make(map[int64]*domain.User)
var articleMap = make(map[int64]*domain.Article)
var commentMap = make(map[int64]*domain.ArticleComment)
lo.ForEach(list, func(item *domain.UserLoveFlag, index int) {
var (
company *domain.Company
user *domain.User
article *domain.Article
comment *domain.ArticleComment
)
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.UserId, l.svcCtx.UserRepository.FindOne)
if user != nil {
company, _ = domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne)
}
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
// 点赞评论
if item.CommentId != 0 {
comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.ArticleCommentRepository.FindOne)
}
resp.List = append(resp.List, l.NewItemSimple(item, user, article, comment))
resp.List = append(resp.List, l.NewItemSimple(item, company, user, article, comment))
})
return resp, nil
}
func (l *MiniMyBeLikedLogic) NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyBeLikedItem {
func (l *MiniMyBeLikedLogic) NewItemSimple(love *domain.UserLoveFlag, company *domain.Company, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyBeLikedItem {
item := types.MyBeLikedItem{
UserId: love.UserId,
ArticleId: love.ArticleId,
... ... @@ -84,6 +89,9 @@ func (l *MiniMyBeLikedLogic) NewItemSimple(love *domain.UserLoveFlag, user *doma
Avatar: user.Avatar,
Position: user.Position,
}
if company != nil {
item.User.CompanyName = company.Name
}
}
if article != nil {
... ...
... ... @@ -45,30 +45,35 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types.
return resp, nil
}
var companyMap = make(map[int64]*domain.Company)
var userMap = make(map[int64]*domain.User)
var articleMap = make(map[int64]*domain.Article)
var commentMap = make(map[int64]*domain.ArticleComment)
lo.ForEach(list, func(item *domain.UserLoveFlag, index int) {
var (
company *domain.Company
user *domain.User
article *domain.Article
comment *domain.ArticleComment
)
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.ToUserId, l.svcCtx.UserRepository.FindOne)
if user != nil {
company, _ = domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne)
}
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
// 点赞评论
if item.CommentId != 0 {
comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.ArticleCommentRepository.FindOne)
}
resp.List = append(resp.List, l.NewItemSimple(item, user, article, comment))
resp.List = append(resp.List, l.NewItemSimple(item, company, user, article, comment))
})
return resp, nil
}
func (l *MiniMyLikeLogic) NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyLikeItem {
func (l *MiniMyLikeLogic) NewItemSimple(love *domain.UserLoveFlag, company *domain.Company, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyLikeItem {
item := types.MyLikeItem{
UserId: love.ToUserId,
ArticleId: love.ArticleId,
... ... @@ -84,6 +89,9 @@ func (l *MiniMyLikeLogic) NewItemSimple(love *domain.UserLoveFlag, user *domain.
Avatar: user.Avatar,
Position: user.Position,
}
if company != nil {
item.User.CompanyName = company.Name
}
}
if article != nil {
... ...