作者 tangxvhui

调试 接口删除评论

... ... @@ -146,9 +146,9 @@ type (
// 小程序删除单个文章的评论
type (
MiniDeleteArticleCommentRequest {
CommentId int64 `json:"commentId"`
UserId int64 `json:",optional"`
CompanyId int64 `json:",optional"`
CommentId int64 `path:"id"`
UserId int64 `path:",optional"`
CompanyId int64 `path:",optional"`
}
MiniDeleteArticleCommentResponse {
Id int64 `json:"id"`
... ...
... ... @@ -5,6 +5,7 @@ import (
"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"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
... ... @@ -39,7 +40,29 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini
commetInfo.Show = domain.CommentShowDisable
_, err = l.svcCtx.ArticleCommentRepository.Update(l.ctx, conn, commetInfo)
// 变更回复数量
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo)
if err != nil {
return err
}
// 减少上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid)
if err != nil {
return err
}
}
// 减少最顶层的评论回复计数
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.TopId)
if err != nil {
return err
}
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
}
... ...
... ... @@ -36,7 +36,11 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
if commentInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有查看权限")
}
queryOption := domain.NewQueryOptions().MustWithKV("topId", commentInfo.Id).WithFindOnly()
if commentInfo.Show == domain.CommentShowDisable {
return nil, xerr.NewErrMsg("没有查看权限")
}
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("topId", commentInfo.Id).MustWithKV("show", domain.CommentShowEnable)
//获取回复的评论
_, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
... ...
... ... @@ -97,9 +97,9 @@ type MiniGetArticleCommentResponse struct {
}
type MiniDeleteArticleCommentRequest struct {
CommentId int64 `json:"commentId"`
UserId int64 `json:",optional"`
CompanyId int64 `json:",optional"`
CommentId int64 `path:"id"`
UserId int64 `path:",optional"`
CompanyId int64 `path:",optional"`
}
type MiniDeleteArticleCommentResponse struct {
... ...
... ... @@ -127,6 +127,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
if v, ok := queryOptions["topId"]; ok {
tx = tx.Where("top_id", v)
}
if v, ok := queryOptions["show"]; ok {
tx = tx.Where("show", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...