|
|
package user
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"github.com/samber/lo"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
|
|
|
|
|
type MiniMyBeLikedLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewMiniMyBeLikedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniMyBeLikedLogic {
|
|
|
return &MiniMyBeLikedLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l *MiniMyBeLikedLogic) MiniMyBeLiked(req *types.MiniBeLikedRequest) (resp *types.MiniBeLikedResponse, err error) {
|
|
|
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
|
|
|
total, list, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
|
|
WithOffsetLimit(req.Page, req.Size).
|
|
|
WithKV("commentId", userToken.CompanyId).
|
|
|
WithKV("toUserId", userToken.UserId))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
resp = &types.MiniBeLikedResponse{}
|
|
|
resp.Total = total
|
|
|
resp.List = make([]types.MyBeLikedItem, 0)
|
|
|
if total == 0 || len(list) == 0 {
|
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
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 (
|
|
|
user *domain.User
|
|
|
article *domain.Article
|
|
|
comment *domain.ArticleComment
|
|
|
)
|
|
|
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.UserId, l.svcCtx.UserRepository.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))
|
|
|
})
|
|
|
|
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
func (l *MiniMyBeLikedLogic) NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyBeLikedItem {
|
|
|
item := types.MyBeLikedItem{
|
|
|
UserId: love.UserId,
|
|
|
ArticleId: love.ArticleId,
|
|
|
CommentId: love.CommentId,
|
|
|
CreatedAt: love.CreatedAt,
|
|
|
}
|
|
|
|
|
|
if user != nil {
|
|
|
item.User = &types.SimpleUser{
|
|
|
Id: user.Id,
|
|
|
CompanyId: user.CompanyId,
|
|
|
Name: user.Name,
|
|
|
Avatar: user.Avatar,
|
|
|
Position: user.Position,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if article != nil {
|
|
|
item.Article = &types.SimpleArticle{
|
|
|
Id: article.Id,
|
|
|
Title: article.Title,
|
|
|
Summary: article.Summary,
|
|
|
CountLove: article.CountLove,
|
|
|
CountComment: article.CountComment,
|
|
|
Show: int(article.Show),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if comment != nil {
|
|
|
item.Comment = &types.SimpleComment{
|
|
|
Id: comment.Id,
|
|
|
Content: comment.Content,
|
|
|
CountLove: comment.CountUserLove,
|
|
|
CountComment: comment.CountReply,
|
|
|
Show: int(comment.Show),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return item
|
|
|
} |
...
|
...
|
|