作者 tangxvhui

调试 接口删除评论

@@ -146,9 +146,9 @@ type ( @@ -146,9 +146,9 @@ type (
146 // 小程序删除单个文章的评论 146 // 小程序删除单个文章的评论
147 type ( 147 type (
148 MiniDeleteArticleCommentRequest { 148 MiniDeleteArticleCommentRequest {
149 - CommentId int64 `json:"commentId"`  
150 - UserId int64 `json:",optional"`  
151 - CompanyId int64 `json:",optional"` 149 + CommentId int64 `path:"id"`
  150 + UserId int64 `path:",optional"`
  151 + CompanyId int64 `path:",optional"`
152 } 152 }
153 MiniDeleteArticleCommentResponse { 153 MiniDeleteArticleCommentResponse {
154 Id int64 `json:"id"` 154 Id int64 `json:"id"`
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 5
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
10 11
@@ -39,7 +40,29 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini @@ -39,7 +40,29 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini
39 40
40 commetInfo.Show = domain.CommentShowDisable 41 commetInfo.Show = domain.CommentShowDisable
41 42
42 - _, err = l.svcCtx.ArticleCommentRepository.Update(l.ctx, conn, commetInfo) 43 + // 变更回复数量
  44 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
  45 + _, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo)
  46 + if err != nil {
  47 + return err
  48 + }
  49 + // 减少上级评论的回复数量
  50 + if commetInfo.Pid != 0 {
  51 + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid)
  52 + if err != nil {
  53 + return err
  54 + }
  55 + }
  56 + // 减少最顶层的评论回复计数
  57 + if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
  58 + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.TopId)
  59 + if err != nil {
  60 + return err
  61 + }
  62 + }
  63 + return nil
  64 + }, true)
  65 +
43 if err != nil { 66 if err != nil {
44 return nil, xerr.NewErrMsgErr("删除评论信息失败", err) 67 return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
45 } 68 }
@@ -36,7 +36,11 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -36,7 +36,11 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
36 if commentInfo.CompanyId != req.CompanyId { 36 if commentInfo.CompanyId != req.CompanyId {
37 return nil, xerr.NewErrMsg("没有查看权限") 37 return nil, xerr.NewErrMsg("没有查看权限")
38 } 38 }
39 - queryOption := domain.NewQueryOptions().MustWithKV("topId", commentInfo.Id).WithFindOnly() 39 +
  40 + if commentInfo.Show == domain.CommentShowDisable {
  41 + return nil, xerr.NewErrMsg("没有查看权限")
  42 + }
  43 + queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("topId", commentInfo.Id).MustWithKV("show", domain.CommentShowEnable)
40 //获取回复的评论 44 //获取回复的评论
41 _, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption) 45 _, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
42 46
@@ -97,9 +97,9 @@ type MiniGetArticleCommentResponse struct { @@ -97,9 +97,9 @@ type MiniGetArticleCommentResponse struct {
97 } 97 }
98 98
99 type MiniDeleteArticleCommentRequest struct { 99 type MiniDeleteArticleCommentRequest struct {
100 - CommentId int64 `json:"commentId"`  
101 - UserId int64 `json:",optional"`  
102 - CompanyId int64 `json:",optional"` 100 + CommentId int64 `path:"id"`
  101 + UserId int64 `path:",optional"`
  102 + CompanyId int64 `path:",optional"`
103 } 103 }
104 104
105 type MiniDeleteArticleCommentResponse struct { 105 type MiniDeleteArticleCommentResponse struct {
@@ -127,6 +127,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans @@ -127,6 +127,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
127 if v, ok := queryOptions["topId"]; ok { 127 if v, ok := queryOptions["topId"]; ok {
128 tx = tx.Where("top_id", v) 128 tx = tx.Where("top_id", v)
129 } 129 }
  130 + if v, ok := queryOptions["show"]; ok {
  131 + tx = tx.Where("show", v)
  132 + }
130 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 133 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
131 return dms, tx.Error 134 return dms, tx.Error
132 } 135 }