作者 tangxvhui

调试编辑评论的接口

... ... @@ -67,6 +67,10 @@ service Core {
@doc "管理后台变更评论的显示状态"
@handler SystemEditAticleCommentShow
post /article_comment/edit_show (SystemEditCommentShowRequest)returns (SystemEditCommentShowResponse)
@doc "管理后台变更评论"
@handler SystemEditAticleComment
post /article_comment/edit (SystemEditCommentRequest)returns (SystemEditCommentResponse)
}
//评论的填写人
... ... @@ -312,14 +316,29 @@ type (
}
)
// 管理后台单独设置评论显示隐藏状态
type (
SystemEditCommentShowRequest {
CompanyId int64 `json:",optional"`
Id []int64 `json:"id"`
Show int `json:"show"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
}
SystemEditCommentShowResponse {
Id []int64 `json:"id"`
}
)
// 管理后台变更评论
type (
SystemEditCommentRequest {
CompanyId int64 `json:",optional"`
Id int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
CountAdminLove int `json:"countAdminLove,optional"`
}
SystemEditCommentResponse {
Id int64 `json:"id"`
}
)
\ No newline at end of file
... ...
package comment
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"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/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func SystemEditAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemEditCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := comment.NewSystemEditAticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.SystemEditAticleComment(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -84,6 +84,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article_comment/edit_show",
Handler: comment.SystemEditAticleCommentShowHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/edit",
Handler: comment.SystemEditAticleCommentHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
... ...
... ... @@ -38,6 +38,12 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini
return nil, xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowDisable {
resp = &types.MiniDeleteArticleCommentResponse{
Id: commetInfo.Id,
}
return resp, nil
}
commetInfo.Show = domain.CommentShowDisable
// 变更回复数量
... ...
... ... @@ -25,6 +25,7 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont
}
}
// 小程序端获取 根据文章id 获取评论列表
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
// 先获取最顶层的评论
var conn = l.svcCtx.DefaultDBConn()
... ...
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"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemEditAticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemEditAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemEditAticleCommentLogic {
return &SystemEditAticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 管理后台变更评论的设置
func (l *SystemEditAticleCommentLogic) SystemEditAticleComment(req *types.SystemEditCommentRequest) (resp *types.SystemEditCommentResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
}
if commetInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有操作权限")
}
commetInfo.CountAdminLove = req.CountAdminLove
var increaseCount int
switch req.Show {
case 1:
// 设置为显示评论
if commetInfo.Show != domain.CommentShowEnable {
commetInfo.Show = domain.CommentShowEnable
increaseCount = 1
}
case 2:
// 设置为隐藏评论
if commetInfo.Show != domain.CommentShowDisable {
commetInfo.Show = domain.CommentShowDisable
increaseCount = -1
}
}
commetInfo.Show = domain.CommentShowEnable
// 变更回复数量
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 increaseCount != 0 {
// 增加上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, increaseCount, commetInfo.Pid)
if err != nil {
return err
}
}
// 增加最顶层的评论回复计数
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, increaseCount, commetInfo.TopId)
if err != nil {
return err
}
}
// 增加加段落评论计数
if commetInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, increaseCount, commetInfo.SectionId)
if err != nil {
return err
}
}
// 增加文章的评论数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, increaseCount, commetInfo.ArticleId)
if err != nil {
return err
}
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
}
resp = &types.SystemEditCommentResponse{
Id: commetInfo.Id,
}
return resp, nil
}
... ...
... ... @@ -26,6 +26,7 @@ func NewSystemEditAticleCommentShowLogic(ctx context.Context, svcCtx *svc.Servic
}
}
// 管理后台,单独设置评论的隐藏显示
func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *types.SystemEditCommentShowRequest) (resp *types.SystemEditCommentShowResponse, err error) {
resp = &types.SystemEditCommentShowResponse{
... ... @@ -35,7 +36,7 @@ func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *type
for _, val := range req.Id {
err = l.enableShow(val, req.CompanyId)
if err != nil {
err = xerr.NewErrMsgErr("操作失败", err)
err = xerr.NewErrMsgErr("操作失败,刷新重试", err)
} else {
resp.Id = append(resp.Id, val)
}
... ... @@ -45,13 +46,15 @@ func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *type
for _, val := range req.Id {
err = l.disableShow(val, req.CompanyId)
if err != nil {
err = xerr.NewErrMsgErr("操作失败", err)
err = xerr.NewErrMsgErr("操作失败,刷新重试", err)
} else {
resp.Id = append(resp.Id, val)
}
}
}
if err != nil {
return resp, err
}
return
}
... ... @@ -61,7 +64,7 @@ func (l *SystemEditAticleCommentShowLogic) disableShow(commentId int64, companyI
if err != nil {
return xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.CompanyId != commentId {
if commetInfo.CompanyId != companyId {
return xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowDisable {
... ... @@ -115,7 +118,7 @@ func (l *SystemEditAticleCommentShowLogic) enableShow(commentId int64, companyId
if err != nil {
return xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.CompanyId != commentId {
if commetInfo.CompanyId != companyId {
return xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowEnable {
... ...
... ... @@ -3,6 +3,8 @@ package user
import (
"context"
"fmt"
"strconv"
"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/domain"
... ... @@ -10,7 +12,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -94,3 +95,9 @@ func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) (
}
return
}
// 后台登录时 ,检查/设置公司的初始数据
func (l *SystemUserInfoLogic) initSystemData(companyId int64) error {
// TODO 初始设置文章标签
return nil
}
... ...
... ... @@ -227,13 +227,24 @@ type SystemGetCommentResponse struct {
type SystemEditCommentShowRequest struct {
CompanyId int64 `json:",optional"`
Id []int64 `json:"id"`
Show int `json:"show"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
}
type SystemEditCommentShowResponse struct {
Id []int64 `json:"id"`
}
type SystemEditCommentRequest struct {
CompanyId int64 `json:",optional"`
Id int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
CountAdminLove int `json:"countAdminLove,optional"`
}
type SystemEditCommentResponse struct {
Id int64 `json:"id"`
}
type MessageSystemRequest struct {
Page int `json:"page"`
Size int `json:"size"`
... ...