From d494eb921b465406f5e51b1bb7d3e9077acd3379 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 1 May 2024 02:51:47 +0800 Subject: [PATCH] by Robin at 20240501 --- api/errcode/errcode.go | 2 + api/proto/zonemoment/proto/not_null_def_op.go | 8 ++++ api/proto/zonemoment/proto/zonemoment_op.go | 14 ++++++ app/mix/controller/init.go | 1 + app/mix/controller/zonemoment_op.go | 12 +++++ app/mix/service/logic/zonemoment.go | 2 +- app/mix/service/service.go | 47 ++++++++++++++++++- 7 files changed, 84 insertions(+), 2 deletions(-) diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index df4a1d77..16fdf437 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -179,6 +179,7 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeZoneMomentNotExist: "私密圈动态不存在", ErrCodePaidZoneMomentCreateTimesReachedUpperbound: "付费动态不能多于免费动态", ErrCodeZoneMomentImagesNotEnoughForEncryption: "预览图片数不得大于等于上传图片数", + ErrCodeZoneMomentStatusNotPublic: "私密圈动态状态不为公开!", ErrCodeZoneMomentThumbsUpSrvFail: "私密圈点赞服务错误", ErrCodeZoneMomentThumbsUpNotExist: "私密圈点赞不存在", @@ -455,6 +456,7 @@ const ( ErrCodeZoneMomentNotExist ErrCode = -34002 // 私密圈动态不存在 ErrCodePaidZoneMomentCreateTimesReachedUpperbound ErrCode = -34003 // 私密圈付费动态创建次数已达上限 ErrCodeZoneMomentImagesNotEnoughForEncryption ErrCode = -34004 // 私密圈图片贴图片数量少于可预览图片数 + ErrCodeZoneMomentStatusNotPublic ErrCode = -34005 // 私密圈动态非公开状态 // ZoneMomentThumbsUp: 35xxx ErrCodeZoneMomentThumbsUpSrvOk ErrCode = ErrCodeOk diff --git a/api/proto/zonemoment/proto/not_null_def_op.go b/api/proto/zonemoment/proto/not_null_def_op.go index 3d2e0230..b57c3124 100644 --- a/api/proto/zonemoment/proto/not_null_def_op.go +++ b/api/proto/zonemoment/proto/not_null_def_op.go @@ -75,3 +75,11 @@ func (p *OpHeadReq) ProvideNotNullValue() (params []*validator.JsonParam) { return } + +func (p *OpSetPrivateReq) ProvideNotNullValue() (params []*validator.JsonParam) { + params = make([]*validator.JsonParam, 0) + + params = append(params, validator.NewInt64PtrParam("请确认待审批动态的id!", p.ZoneMomentId)) + + return +} diff --git a/api/proto/zonemoment/proto/zonemoment_op.go b/api/proto/zonemoment/proto/zonemoment_op.go index ef6a29dd..efc2e998 100644 --- a/api/proto/zonemoment/proto/zonemoment_op.go +++ b/api/proto/zonemoment/proto/zonemoment_op.go @@ -209,3 +209,17 @@ type OpHeadResp struct { base.BaseResponse Data *OpHeadData `json:"data"` } + +// op 退回动态 +type OpSetPrivateReq struct { + base.BaseRequest + ZoneMomentId *int64 `json:"zone_moment_id"` +} + +type OpSetPrivateData struct { +} + +type OpSetPrivateResp struct { + base.BaseResponse + Data *OpSetPrivateData `json:"data"` +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 9386715d..01a871a6 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -509,6 +509,7 @@ func Init(r *gin.Engine) { opZoneMomentGroup.POST("list_by_user_id", middleware.JSONParamValidator(zonemomentproto.OpListByUserIdReq{}), middleware.JwtAuthenticator(), OpGetZoneMomentListByUserId) opZoneMomentGroup.POST("review", middleware.JSONParamValidator(zonemomentproto.OpReviewReq{}), middleware.JwtAuthenticator(), OpReviewZoneMoment) opZoneMomentGroup.POST("head", middleware.JSONParamValidator(zonemomentproto.OpHeadReq{}), middleware.JwtAuthenticator(), OpHeadZoneMoment) + opZoneMomentGroup.POST("set_private", middleware.JSONParamValidator(zonemomentproto.OpSetPrivateReq{}), middleware.JwtAuthenticator(), OpSetPrivateZoneMoment) // 视频审核callback extVideoModerationGroup := r.Group("/ext/video_moderation") diff --git a/app/mix/controller/zonemoment_op.go b/app/mix/controller/zonemoment_op.go index 165e3aa6..f5d63883 100644 --- a/app/mix/controller/zonemoment_op.go +++ b/app/mix/controller/zonemoment_op.go @@ -135,3 +135,15 @@ func OpHeadZoneMoment(ctx *gin.Context) { ReplyOk(ctx, nil) } + +func OpSetPrivateZoneMoment(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*zonemomentproto.OpSetPrivateReq) + ec := service.DefaultService.OpSetPrivateZoneMoment(ctx, req) + if ec != errcode.ErrCodeZoneMomentSrvOk { + logger.Error("OpSetPrivateZoneMoment fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + ReplyOk(ctx, nil) +} diff --git a/app/mix/service/logic/zonemoment.go b/app/mix/service/logic/zonemoment.go index ec63cf25..91fc25a4 100644 --- a/app/mix/service/logic/zonemoment.go +++ b/app/mix/service/logic/zonemoment.go @@ -75,7 +75,7 @@ func (p *ZoneMoment) OpList(ctx *gin.Context, req *zonemomentproto.OpListReq) ([ func (p *ZoneMoment) GetById(ctx *gin.Context, id int64) (*dbstruct.ZoneMoment, error) { zonemoment, err := p.store.GetZoneMomentById(ctx, id) if err != nil { - logger.Error("GetZoneMomentList fail, err: %v", err) + logger.Error("GetZoneMomentById fail, err: %v", err) return &dbstruct.ZoneMoment{}, err } return zonemoment, nil diff --git a/app/mix/service/service.go b/app/mix/service/service.go index f1d1cde1..520c9944 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -3601,7 +3601,7 @@ func (s *Service) OpHeadZoneMoment(ctx *gin.Context, req *zonemomentproto.OpHead // 更新动态的状态 err := _DefaultZoneMoment.OpHeadByIds(ctx, req.ZoneMomentIds, req.OpType) if err != nil { - logger.Error("_DefaultZoneMoment OpIncPriorityByIds fail, req: %v, err: %v", util.ToJson(req), err) + logger.Error("_DefaultZoneMoment OpHeadByIds fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeZoneMomentSrvFail return } @@ -3609,6 +3609,51 @@ func (s *Service) OpHeadZoneMoment(ctx *gin.Context, req *zonemomentproto.OpHead return } +func (s *Service) OpSetPrivateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpSetPrivateReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeZoneMomentSrvOk + + // 保证动态的状态都是公开的 + zonemoment, err := _DefaultZoneMoment.GetById(ctx, util.DerefInt64(req.ZoneMomentId)) + if err != nil { + logger.Error("_DefaultZoneMoment GetById fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneMomentSrvFail + return + } + if zonemoment == nil { + ec = errcode.ErrCodeZoneMomentNotExist + return + } + if zonemoment.GetStatus() != consts.ZoneMoment_Public { + ec = errcode.ErrCodeZoneMomentStatusNotPublic + return + } + + // 更新动态的状态 + err = _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{ + ZoneMoment: &dbstruct.ZoneMoment{ + Id: req.ZoneMomentId, + Status: goproto.Int64(consts.ZoneMoment_Private), + }, + }) + if err != nil { + logger.Error("_DefaultZoneMoment OpUpdate fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneMomentSrvFail + return + } + + // 回退空间内统计总数 + mediaCountInc := len(zonemoment.MediaComp.GetImageIds()) + videoCountInc := len(zonemoment.MediaComp.GetVideoIds()) + err = _DefaultZone.RecordStatisticsById(ctx, zonemoment.GetZid(), -1, -int64(mediaCountInc), -int64(videoCountInc)) + if err != nil { + logger.Error("RecordStatisticsById fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneSrvFail + return + } + + return +} + // ZoneThirdPartner func (s *Service) OpCreateZoneThirdPartner(ctx *gin.Context, req *zone_third_partner_proto.OpCreateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneThirdPartnerSrvOk