作者 tangxvhui

调整 编辑运营点赞接口的 参数结构

@@ -376,12 +376,14 @@ type ( @@ -376,12 +376,14 @@ type (
376 // 管理后台变更评论的运营点赞 376 // 管理后台变更评论的运营点赞
377 type ( 377 type (
378 SystemEditCommentLoveRequest { 378 SystemEditCommentLoveRequest {
379 - CompanyId int64 `json:",optional"` 379 + CompanyId int64 `json:",optional"`
  380 + ParamList []SystemEditLove `json:"paramList"`
  381 + }
  382 + SystemEditLove {
380 Id int64 `json:"id"` 383 Id int64 `json:"id"`
381 CountAdminLove int `json:"countAdminLove,optional"` 384 CountAdminLove int `json:"countAdminLove,optional"`
382 } 385 }
383 -  
384 SystemEditCommentLoveResponse { 386 SystemEditCommentLoveResponse {
385 - Id int64 `json:"id"` 387 + ParamList []SystemEditLove `json:"paramList"`
386 } 388 }
387 ) 389 )
@@ -5,6 +5,8 @@ import ( @@ -5,6 +5,8 @@ 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"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
9 11
10 "github.com/zeromicro/go-zero/core/logx" 12 "github.com/zeromicro/go-zero/core/logx"
@@ -26,24 +28,47 @@ func NewSystemEditAticleCommentLoveLogic(ctx context.Context, svcCtx *svc.Servic @@ -26,24 +28,47 @@ func NewSystemEditAticleCommentLoveLogic(ctx context.Context, svcCtx *svc.Servic
26 28
27 func (l *SystemEditAticleCommentLoveLogic) SystemEditAticleCommentLove(req *types.SystemEditCommentLoveRequest) (resp *types.SystemEditCommentLoveResponse, err error) { 29 func (l *SystemEditAticleCommentLoveLogic) SystemEditAticleCommentLove(req *types.SystemEditCommentLoveRequest) (resp *types.SystemEditCommentLoveResponse, err error) {
28 var conn = l.svcCtx.DefaultDBConn() 30 var conn = l.svcCtx.DefaultDBConn()
29 - if req.CountAdminLove < 0 {  
30 - return nil, xerr.NewErrMsg("运营点赞数不能小于0") 31 +
  32 + if len(req.ParamList) > 0 {
  33 + return &types.SystemEditCommentLoveResponse{}, nil
  34 + }
  35 + paramMap := map[int64]int{}
  36 + ids := []int64{}
  37 + for _, val := range req.ParamList {
  38 + if val.CountAdminLove < 0 {
  39 + return nil, xerr.NewErrMsg("运营点赞数不能小于0")
  40 + }
  41 + ids = append(ids, val.Id)
  42 + paramMap[val.Id] = val.CountAdminLove
31 } 43 }
32 - commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.Id) 44 +
  45 + queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("ids", ids)
  46 + _, commetList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
33 if err != nil { 47 if err != nil {
34 return nil, xerr.NewErrMsgErr("编辑评论信息失败", err) 48 return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
35 } 49 }
36 - if commetInfo.CompanyId != req.CompanyId {  
37 - return nil, xerr.NewErrMsg("没有操作权限") 50 + resp = &types.SystemEditCommentLoveResponse{}
  51 + for _, val := range commetList {
  52 + if u, ok := paramMap[val.Id]; ok {
  53 + val.CountAdminLove = u
  54 + resp.ParamList = append(resp.ParamList, types.SystemEditLove{
  55 + Id: val.Id,
  56 + CountAdminLove: val.CountAdminLove,
  57 + })
  58 + }
38 } 59 }
39 -  
40 - commetInfo.CountAdminLove = req.CountAdminLove  
41 - _, err = l.svcCtx.ArticleCommentRepository.Update(l.ctx, conn, commetInfo) 60 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
  61 + for _, val := range commetList {
  62 + _, err := l.svcCtx.ArticleCommentRepository.Update(ctx, c, val)
  63 + if err != nil {
  64 + return err
  65 + }
  66 + }
  67 + return nil
  68 + }, true)
42 if err != nil { 69 if err != nil {
43 return nil, xerr.NewErrMsgErr("编辑评论信息失败", err) 70 return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
44 } 71 }
45 - resp = &types.SystemEditCommentLoveResponse{  
46 - Id: commetInfo.Id,  
47 - }  
48 - return 72 +
  73 + return resp, nil
49 } 74 }
@@ -276,13 +276,17 @@ type SystemEditCommentResponse struct { @@ -276,13 +276,17 @@ type SystemEditCommentResponse struct {
276 } 276 }
277 277
278 type SystemEditCommentLoveRequest struct { 278 type SystemEditCommentLoveRequest struct {
279 - CompanyId int64 `json:",optional"` 279 + CompanyId int64 `json:",optional"`
  280 + ParamList []SystemEditLove `json:"paramList"`
  281 +}
  282 +
  283 +type SystemEditLove struct {
280 Id int64 `json:"id"` 284 Id int64 `json:"id"`
281 CountAdminLove int `json:"countAdminLove,optional"` 285 CountAdminLove int `json:"countAdminLove,optional"`
282 } 286 }
283 287
284 type SystemEditCommentLoveResponse struct { 288 type SystemEditCommentLoveResponse struct {
285 - Id int64 `json:"id"` 289 + ParamList []SystemEditLove `json:"paramList"`
286 } 290 }
287 291
288 type MessageRequest struct { 292 type MessageRequest struct {