|
|
package comment
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
|
|
|
"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/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
|
|
|
|
|
type MiniTop5ArticleCommentLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewMiniTop5ArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniTop5ArticleCommentLogic {
|
|
|
return &MiniTop5ArticleCommentLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取前5的评论
|
|
|
func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5ArticleCommentRequest) (resp *types.MiniTop5ArticleCommentResponse, err error) {
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
commentList, err := l.svcCtx.ArticleCommentRepository.Top5Comment(l.ctx, conn, req.CompanyId, req.ArticleId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
}
|
|
|
|
|
|
queryOption := domain.NewQueryOptions().WithFindOnly().
|
|
|
MustWithKV("articleId", req.ArticleId).
|
|
|
MustWithKV("userId", req.UserId)
|
|
|
// 获取我点赞的评论
|
|
|
_, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
}
|
|
|
// 我点赞的
|
|
|
flagMap := map[int64]struct{}{}
|
|
|
for _, val := range userFlagList {
|
|
|
flagMap[val.CommentId] = struct{}{}
|
|
|
}
|
|
|
|
|
|
resp = &types.MiniTop5ArticleCommentResponse{
|
|
|
List: make([]types.ArticleCommentItem, len(commentList)),
|
|
|
}
|
|
|
for i, val := range commentList {
|
|
|
item := types.ArticleCommentItem{
|
|
|
Id: val.Id,
|
|
|
Pid: val.Pid,
|
|
|
TopId: val.TopId,
|
|
|
ArtitcleId: val.ArticleId,
|
|
|
SectionId: val.SectionId,
|
|
|
FromUserId: val.FromUserId,
|
|
|
FromUser: types.CommentAuthor{
|
|
|
Id: val.FromUser.Id,
|
|
|
Name: val.FromUser.Name,
|
|
|
Avatar: val.FromUser.Avatar,
|
|
|
Position: val.FromUser.Position,
|
|
|
Company: val.FromUser.Company,
|
|
|
},
|
|
|
ToUserId: val.ToUserId,
|
|
|
ToUser: types.CommentAuthor{
|
|
|
Id: val.ToUser.Id,
|
|
|
Name: val.ToUser.Name,
|
|
|
Avatar: val.ToUser.Avatar,
|
|
|
Position: val.ToUser.Position,
|
|
|
Company: val.ToUser.Company,
|
|
|
},
|
|
|
SectionContent: val.SectionContent,
|
|
|
CountReply: val.CountReply,
|
|
|
CountUserLove: val.CountUserLove,
|
|
|
CountAdminLove: val.CountAdminLove,
|
|
|
AtWho: []types.CommentAtWho{},
|
|
|
CreatedAt: val.CreatedAt,
|
|
|
MeLoveFlag: 0,
|
|
|
}
|
|
|
|
|
|
if _, ok := flagMap[val.Id]; ok {
|
|
|
item.MeLoveFlag = 1
|
|
|
}
|
|
|
for _, val2 := range val.AtWho {
|
|
|
item.AtWho = append(item.AtWho, types.CommentAtWho{
|
|
|
Id: val2.Id,
|
|
|
Name: val2.Name,
|
|
|
})
|
|
|
}
|
|
|
resp.List[i] = item
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|