...
|
...
|
@@ -2,6 +2,7 @@ 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/db/transaction"
|
...
|
...
|
@@ -44,13 +45,32 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini |
|
|
return resp, nil
|
|
|
}
|
|
|
commentInfo.Show = domain.CommentShowDisable
|
|
|
|
|
|
var childComment []*domain.ArticleComment
|
|
|
if commentInfo.Pid == 0 {
|
|
|
_, childComment, err = l.svcCtx.ArticleCommentRepository.Find(
|
|
|
l.ctx,
|
|
|
conn,
|
|
|
domain.NewQueryOptions().WithFindOnly().MustWithKV("topId", commentInfo.Id),
|
|
|
)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
|
|
|
}
|
|
|
}
|
|
|
for _, val := range childComment {
|
|
|
val.Show = domain.CommentShowDisable
|
|
|
}
|
|
|
// 变更回复数量
|
|
|
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
|
|
|
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commentInfo)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
for _, val := range childComment {
|
|
|
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, val)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 减少上级评论的回复数量
|
|
|
if commentInfo.Pid != 0 {
|
|
|
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commentInfo.Pid)
|
...
|
...
|
@@ -67,13 +87,13 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini |
|
|
}
|
|
|
//减少加段落评论计数
|
|
|
if commentInfo.SectionId > 0 {
|
|
|
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commentInfo.SectionId)
|
|
|
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -(len(childComment) + 1), commentInfo.SectionId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 减少文章的评论数
|
|
|
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commentInfo.ArticleId)
|
|
|
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -(len(childComment) + 1), commentInfo.ArticleId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
...
|
...
|
|