作者 tangxvhui

调试编辑评论的接口

@@ -67,6 +67,10 @@ service Core { @@ -67,6 +67,10 @@ service Core {
67 @doc "管理后台变更评论的显示状态" 67 @doc "管理后台变更评论的显示状态"
68 @handler SystemEditAticleCommentShow 68 @handler SystemEditAticleCommentShow
69 post /article_comment/edit_show (SystemEditCommentShowRequest)returns (SystemEditCommentShowResponse) 69 post /article_comment/edit_show (SystemEditCommentShowRequest)returns (SystemEditCommentShowResponse)
  70 +
  71 + @doc "管理后台变更评论"
  72 + @handler SystemEditAticleComment
  73 + post /article_comment/edit (SystemEditCommentRequest)returns (SystemEditCommentResponse)
70 } 74 }
71 75
72 //评论的填写人 76 //评论的填写人
@@ -312,14 +316,29 @@ type ( @@ -312,14 +316,29 @@ type (
312 } 316 }
313 ) 317 )
314 318
  319 +// 管理后台单独设置评论显示隐藏状态
315 type ( 320 type (
316 SystemEditCommentShowRequest { 321 SystemEditCommentShowRequest {
317 CompanyId int64 `json:",optional"` 322 CompanyId int64 `json:",optional"`
318 Id []int64 `json:"id"` 323 Id []int64 `json:"id"`
319 - Show int `json:"show"` 324 + Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
320 } 325 }
321 326
322 SystemEditCommentShowResponse { 327 SystemEditCommentShowResponse {
323 Id []int64 `json:"id"` 328 Id []int64 `json:"id"`
324 } 329 }
325 ) 330 )
  331 +
  332 +// 管理后台变更评论
  333 +type (
  334 + SystemEditCommentRequest {
  335 + CompanyId int64 `json:",optional"`
  336 + Id int64 `json:"id"`
  337 + Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
  338 + CountAdminLove int `json:"countAdminLove,optional"`
  339 + }
  340 +
  341 + SystemEditCommentResponse {
  342 + Id int64 `json:"id"`
  343 + }
  344 +)
  1 +package comment
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  12 +)
  13 +
  14 +func SystemEditAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  15 + return func(w http.ResponseWriter, r *http.Request) {
  16 + var req types.SystemEditCommentRequest
  17 + if err := httpx.Parse(r, &req); err != nil {
  18 + httpx.ErrorCtx(r.Context(), w, err)
  19 + return
  20 + }
  21 +
  22 + l := comment.NewSystemEditAticleCommentLogic(r.Context(), svcCtx)
  23 + token := contextdata.GetUserTokenFromCtx(r.Context())
  24 + req.CompanyId = token.CompanyId
  25 + resp, err := l.SystemEditAticleComment(&req)
  26 + result.HttpResult(r, w, resp, err)
  27 + }
  28 +}
@@ -84,6 +84,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -84,6 +84,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
84 Path: "/article_comment/edit_show", 84 Path: "/article_comment/edit_show",
85 Handler: comment.SystemEditAticleCommentShowHandler(serverCtx), 85 Handler: comment.SystemEditAticleCommentShowHandler(serverCtx),
86 }, 86 },
  87 + {
  88 + Method: http.MethodPost,
  89 + Path: "/article_comment/edit",
  90 + Handler: comment.SystemEditAticleCommentHandler(serverCtx),
  91 + },
87 }..., 92 }...,
88 ), 93 ),
89 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), 94 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
@@ -38,6 +38,12 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini @@ -38,6 +38,12 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini
38 return nil, xerr.NewErrMsg("没有操作权限") 38 return nil, xerr.NewErrMsg("没有操作权限")
39 } 39 }
40 40
  41 + if commetInfo.Show == domain.CommentShowDisable {
  42 + resp = &types.MiniDeleteArticleCommentResponse{
  43 + Id: commetInfo.Id,
  44 + }
  45 + return resp, nil
  46 + }
41 commetInfo.Show = domain.CommentShowDisable 47 commetInfo.Show = domain.CommentShowDisable
42 48
43 // 变更回复数量 49 // 变更回复数量
@@ -25,6 +25,7 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont @@ -25,6 +25,7 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont
25 } 25 }
26 } 26 }
27 27
  28 +// 小程序端获取 根据文章id 获取评论列表
28 func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) { 29 func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
29 // 先获取最顶层的评论 30 // 先获取最顶层的评论
30 var conn = l.svcCtx.DefaultDBConn() 31 var conn = l.svcCtx.DefaultDBConn()
  1 +package comment
  2 +
  3 +import (
  4 + "context"
  5 +
  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"
  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"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  11 +
  12 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type SystemEditAticleCommentLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewSystemEditAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemEditAticleCommentLogic {
  22 + return &SystemEditAticleCommentLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +// 管理后台变更评论的设置
  30 +func (l *SystemEditAticleCommentLogic) SystemEditAticleComment(req *types.SystemEditCommentRequest) (resp *types.SystemEditCommentResponse, err error) {
  31 + var conn = l.svcCtx.DefaultDBConn()
  32 + commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.Id)
  33 + if err != nil {
  34 + return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
  35 + }
  36 + if commetInfo.CompanyId != req.CompanyId {
  37 + return nil, xerr.NewErrMsg("没有操作权限")
  38 + }
  39 + commetInfo.CountAdminLove = req.CountAdminLove
  40 + var increaseCount int
  41 + switch req.Show {
  42 + case 1:
  43 + // 设置为显示评论
  44 + if commetInfo.Show != domain.CommentShowEnable {
  45 + commetInfo.Show = domain.CommentShowEnable
  46 + increaseCount = 1
  47 + }
  48 + case 2:
  49 + // 设置为隐藏评论
  50 + if commetInfo.Show != domain.CommentShowDisable {
  51 + commetInfo.Show = domain.CommentShowDisable
  52 + increaseCount = -1
  53 + }
  54 + }
  55 + commetInfo.Show = domain.CommentShowEnable
  56 + // 变更回复数量
  57 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
  58 + _, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo)
  59 + if err != nil {
  60 + return err
  61 + }
  62 + if increaseCount != 0 {
  63 + // 增加上级评论的回复数量
  64 + if commetInfo.Pid != 0 {
  65 + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, increaseCount, commetInfo.Pid)
  66 + if err != nil {
  67 + return err
  68 + }
  69 + }
  70 + // 增加最顶层的评论回复计数
  71 + if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
  72 + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, increaseCount, commetInfo.TopId)
  73 + if err != nil {
  74 + return err
  75 + }
  76 + }
  77 + // 增加加段落评论计数
  78 + if commetInfo.SectionId > 0 {
  79 + err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, increaseCount, commetInfo.SectionId)
  80 + if err != nil {
  81 + return err
  82 + }
  83 + }
  84 + // 增加文章的评论数
  85 + err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, increaseCount, commetInfo.ArticleId)
  86 + if err != nil {
  87 + return err
  88 + }
  89 + }
  90 + return nil
  91 + }, true)
  92 +
  93 + if err != nil {
  94 + return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
  95 + }
  96 + resp = &types.SystemEditCommentResponse{
  97 + Id: commetInfo.Id,
  98 + }
  99 + return resp, nil
  100 +
  101 +}
@@ -26,6 +26,7 @@ func NewSystemEditAticleCommentShowLogic(ctx context.Context, svcCtx *svc.Servic @@ -26,6 +26,7 @@ func NewSystemEditAticleCommentShowLogic(ctx context.Context, svcCtx *svc.Servic
26 } 26 }
27 } 27 }
28 28
  29 +// 管理后台,单独设置评论的隐藏显示
29 func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *types.SystemEditCommentShowRequest) (resp *types.SystemEditCommentShowResponse, err error) { 30 func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *types.SystemEditCommentShowRequest) (resp *types.SystemEditCommentShowResponse, err error) {
30 31
31 resp = &types.SystemEditCommentShowResponse{ 32 resp = &types.SystemEditCommentShowResponse{
@@ -35,7 +36,7 @@ func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *type @@ -35,7 +36,7 @@ func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *type
35 for _, val := range req.Id { 36 for _, val := range req.Id {
36 err = l.enableShow(val, req.CompanyId) 37 err = l.enableShow(val, req.CompanyId)
37 if err != nil { 38 if err != nil {
38 - err = xerr.NewErrMsgErr("操作失败", err) 39 + err = xerr.NewErrMsgErr("操作失败,刷新重试", err)
39 } else { 40 } else {
40 resp.Id = append(resp.Id, val) 41 resp.Id = append(resp.Id, val)
41 } 42 }
@@ -45,13 +46,15 @@ func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *type @@ -45,13 +46,15 @@ func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *type
45 for _, val := range req.Id { 46 for _, val := range req.Id {
46 err = l.disableShow(val, req.CompanyId) 47 err = l.disableShow(val, req.CompanyId)
47 if err != nil { 48 if err != nil {
48 - err = xerr.NewErrMsgErr("操作失败", err) 49 + err = xerr.NewErrMsgErr("操作失败,刷新重试", err)
49 } else { 50 } else {
50 resp.Id = append(resp.Id, val) 51 resp.Id = append(resp.Id, val)
51 } 52 }
52 } 53 }
53 } 54 }
54 - 55 + if err != nil {
  56 + return resp, err
  57 + }
55 return 58 return
56 } 59 }
57 60
@@ -61,7 +64,7 @@ func (l *SystemEditAticleCommentShowLogic) disableShow(commentId int64, companyI @@ -61,7 +64,7 @@ func (l *SystemEditAticleCommentShowLogic) disableShow(commentId int64, companyI
61 if err != nil { 64 if err != nil {
62 return xerr.NewErrMsgErr("删除评论信息失败", err) 65 return xerr.NewErrMsgErr("删除评论信息失败", err)
63 } 66 }
64 - if commetInfo.CompanyId != commentId { 67 + if commetInfo.CompanyId != companyId {
65 return xerr.NewErrMsg("没有操作权限") 68 return xerr.NewErrMsg("没有操作权限")
66 } 69 }
67 if commetInfo.Show == domain.CommentShowDisable { 70 if commetInfo.Show == domain.CommentShowDisable {
@@ -115,7 +118,7 @@ func (l *SystemEditAticleCommentShowLogic) enableShow(commentId int64, companyId @@ -115,7 +118,7 @@ func (l *SystemEditAticleCommentShowLogic) enableShow(commentId int64, companyId
115 if err != nil { 118 if err != nil {
116 return xerr.NewErrMsgErr("删除评论信息失败", err) 119 return xerr.NewErrMsgErr("删除评论信息失败", err)
117 } 120 }
118 - if commetInfo.CompanyId != commentId { 121 + if commetInfo.CompanyId != companyId {
119 return xerr.NewErrMsg("没有操作权限") 122 return xerr.NewErrMsg("没有操作权限")
120 } 123 }
121 if commetInfo.Show == domain.CommentShowEnable { 124 if commetInfo.Show == domain.CommentShowEnable {
@@ -3,6 +3,8 @@ package user @@ -3,6 +3,8 @@ package user
3 import ( 3 import (
4 "context" 4 "context"
5 "fmt" 5 "fmt"
  6 + "strconv"
  7 +
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 8 "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" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
@@ -10,7 +12,6 @@ import ( @@ -10,7 +12,6 @@ import (
10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" 12 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
11 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool" 13 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
12 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" 14 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
13 - "strconv"  
14 15
15 "github.com/zeromicro/go-zero/core/logx" 16 "github.com/zeromicro/go-zero/core/logx"
16 ) 17 )
@@ -94,3 +95,9 @@ func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) ( @@ -94,3 +95,9 @@ func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) (
94 } 95 }
95 return 96 return
96 } 97 }
  98 +
  99 +// 后台登录时 ,检查/设置公司的初始数据
  100 +func (l *SystemUserInfoLogic) initSystemData(companyId int64) error {
  101 + // TODO 初始设置文章标签
  102 + return nil
  103 +}
@@ -227,13 +227,24 @@ type SystemGetCommentResponse struct { @@ -227,13 +227,24 @@ type SystemGetCommentResponse struct {
227 type SystemEditCommentShowRequest struct { 227 type SystemEditCommentShowRequest struct {
228 CompanyId int64 `json:",optional"` 228 CompanyId int64 `json:",optional"`
229 Id []int64 `json:"id"` 229 Id []int64 `json:"id"`
230 - Show int `json:"show"` 230 + Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
231 } 231 }
232 232
233 type SystemEditCommentShowResponse struct { 233 type SystemEditCommentShowResponse struct {
234 Id []int64 `json:"id"` 234 Id []int64 `json:"id"`
235 } 235 }
236 236
  237 +type SystemEditCommentRequest struct {
  238 + CompanyId int64 `json:",optional"`
  239 + Id int64 `json:"id"`
  240 + Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
  241 + CountAdminLove int `json:"countAdminLove,optional"`
  242 +}
  243 +
  244 +type SystemEditCommentResponse struct {
  245 + Id int64 `json:"id"`
  246 +}
  247 +
237 type MessageSystemRequest struct { 248 type MessageSystemRequest struct {
238 Page int `json:"page"` 249 Page int `json:"page"`
239 Size int `json:"size"` 250 Size int `json:"size"`