|
|
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 MiniGetArticleCommentLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleCommentLogic {
|
|
|
return &MiniGetArticleCommentLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) {
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
//获取主评论
|
|
|
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
}
|
|
|
if commentInfo.CompanyId != req.CompanyId {
|
|
|
return nil, xerr.NewErrMsg("没有查看权限")
|
|
|
}
|
|
|
queryOption := domain.NewQueryOptions().MustWithKV("topId", commentInfo.Id).WithFindOnly()
|
|
|
//获取回复的评论
|
|
|
_, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
}
|
|
|
//TODO 获取我点赞的评论
|
|
|
|
|
|
//混合数据
|
|
|
commentResp := types.ArticleCommentItem{
|
|
|
Id: commentInfo.Id,
|
|
|
Pid: commentInfo.Pid,
|
|
|
TopId: commentInfo.TopId,
|
|
|
ArtitcleId: commentInfo.ArticleId,
|
|
|
SectionId: commentInfo.ArticleId,
|
|
|
FromUserId: commentInfo.FromUserId,
|
|
|
FromUser: types.CommentAuthor{
|
|
|
Id: commentInfo.FromUser.Id,
|
|
|
Name: commentInfo.FromUser.Name,
|
|
|
Avatar: commentInfo.FromUser.Avatar,
|
|
|
Position: commentInfo.FromUser.Position,
|
|
|
Company: commentInfo.FromUser.Company,
|
|
|
},
|
|
|
ToUserId: commentInfo.ToUserId,
|
|
|
ToUser: types.CommentAuthor{
|
|
|
Id: commentInfo.ToUser.Id,
|
|
|
Name: commentInfo.ToUser.Name,
|
|
|
Avatar: commentInfo.ToUser.Avatar,
|
|
|
Position: commentInfo.ToUser.Position,
|
|
|
Company: commentInfo.ToUser.Company,
|
|
|
},
|
|
|
SectionContent: commentInfo.SectionContent,
|
|
|
CountReply: commentInfo.CountReply,
|
|
|
CountUserLove: commentInfo.CountUserLove,
|
|
|
CountAdminLove: commentInfo.CountAdminLove,
|
|
|
AtWho: []types.CommentAuthor{},
|
|
|
CreatedAt: commentInfo.CreatedAt,
|
|
|
}
|
|
|
for _, val := range commentInfo.AtWho {
|
|
|
commentResp.AtWho = append(commentResp.AtWho, types.CommentAuthor{
|
|
|
Id: val.Id,
|
|
|
Name: val.Name,
|
|
|
Avatar: val.Avatar,
|
|
|
Position: val.Position,
|
|
|
Company: val.Company,
|
|
|
})
|
|
|
}
|
|
|
allReply := []types.ArticleCommentItem{}
|
|
|
for _, val := range replyCommenList {
|
|
|
reply := types.ArticleCommentItem{
|
|
|
Id: val.Id,
|
|
|
Pid: val.Pid,
|
|
|
TopId: val.TopId,
|
|
|
ArtitcleId: val.ArticleId,
|
|
|
SectionId: val.ArticleId,
|
|
|
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.CommentAuthor{},
|
|
|
CreatedAt: val.CreatedAt,
|
|
|
}
|
|
|
for _, val2 := range val.AtWho {
|
|
|
reply.AtWho = append(reply.AtWho, types.CommentAuthor{
|
|
|
Id: val2.Id,
|
|
|
Name: val2.Name,
|
|
|
Avatar: val2.Avatar,
|
|
|
Position: val2.Position,
|
|
|
Company: val2.Company,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
resp = &types.MiniGetArticleCommentResponse{
|
|
|
ArticleCommentAndReply: types.ArticleCommentAndReply{
|
|
|
Comment: commentResp,
|
|
|
Reply: allReply,
|
|
|
TotalReply: int64(len(replyCommenList)),
|
|
|
},
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|