|
|
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 MiniMyLikeLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewMiniMyLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniMyLikeLogic {
|
|
|
return &MiniMyLikeLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types.MiniMyLikeResponse, 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("userId", userToken.UserId))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
resp = &types.MiniMyLikeResponse{}
|
|
|
resp.Total = total
|
|
|
resp.List = make([]types.MyLikeItem, 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.Comment)
|
|
|
|
|
|
lo.ForEach(list, func(item *domain.UserLoveFlag, index int) {
|
|
|
var (
|
|
|
user *domain.User
|
|
|
article *domain.Article
|
|
|
comment *domain.Comment
|
|
|
)
|
|
|
|
|
|
if item.CommentId != 0 { // 点赞评论
|
|
|
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.CommentAuthor, l.svcCtx.UserRepository.FindOne)
|
|
|
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
|
|
|
comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.CommentRepository.FindOne)
|
|
|
} else {
|
|
|
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.ArticleAuthor, l.svcCtx.UserRepository.FindOne)
|
|
|
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
|
|
|
}
|
|
|
|
|
|
resp.List = append(resp.List, NewItemSimple(item, user, article, comment))
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.Comment) types.MyLikeItem {
|
|
|
item := types.MyLikeItem{
|
|
|
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,
|
|
|
CountLove: article.CountLove,
|
|
|
CountComment: article.CountComment,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if comment != nil {
|
|
|
item.Comment = &types.SimpleComment{
|
|
|
Id: comment.Id,
|
|
|
//Content: comment.Content,
|
|
|
//CountLove: comment.CountLove,
|
|
|
//CountComment: comment.CountComment,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return item
|
|
|
} |
...
|
...
|
|