From 14d86ae777aa0c24da29d019cc31e2f34283eb85 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Sat, 27 Apr 2024 08:20:19 +0800 Subject: [PATCH] by Robin at 20240427 --- api/consts/consts.go | 2 +- api/errcode/errcode.go | 16 +++++++++------- app/mix/service/apiservice.go | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/api/consts/consts.go b/api/consts/consts.go index 0ff7b398..38ae7b2a 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -50,7 +50,7 @@ const ( MaxDailyMomentCreateTimesKey = "max_daily_moment_create_times" DefaultMomentTextKey = "default_moment_text" MaxDailyZoneMomentCreateTimesKey = "max_daily_zone_moment_create_times" - ZoneKey = "zone" + ReferentialZoneMomentKey = "referential_zone_moment" ) // del_flag diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index e907c631..9d86645a 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -170,9 +170,10 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeAccountCancellationSrvFail: "账户注销服务错误", ErrCodeAccountCancellationNotExist: "账户注销不存在", - ErrCodeZoneSrvFail: "空间服务错误", - ErrCodeZoneNotExist: "空间不存在", - ErrCodeUnlockedZone: "访客未解锁该空间", + ErrCodeZoneSrvFail: "空间服务错误", + ErrCodeZoneNotExist: "空间不存在", + ErrCodeUnlockedZone: "访客未解锁该空间", + ErrCodeZoneDuplicateKey: "空间重复创建", ErrCodeZoneMomentSrvFail: "私密圈动态服务错误", ErrCodeZoneMomentNotExist: "私密圈动态不存在", @@ -442,10 +443,11 @@ const ( ErrCodeAccountPunishmentStreamerOnly ErrCode = -32007 // 该账号处罚仅能对主播进行 // Zone: 33xxx - ErrCodeZoneSrvOk ErrCode = ErrCodeOk - ErrCodeZoneSrvFail ErrCode = -33001 // 空间服务错误 - ErrCodeZoneNotExist ErrCode = -33002 // 空间不存在 - ErrCodeUnlockedZone ErrCode = -33003 // 未解锁的空间 + ErrCodeZoneSrvOk ErrCode = ErrCodeOk + ErrCodeZoneSrvFail ErrCode = -33001 // 空间服务错误 + ErrCodeZoneNotExist ErrCode = -33002 // 空间不存在 + ErrCodeUnlockedZone ErrCode = -33003 // 未解锁的空间 + ErrCodeZoneDuplicateKey ErrCode = -33004 // 空间已存在 // ZoneMoment: 34xxx ErrCodeZoneMomentSrvOk ErrCode = ErrCodeOk diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index de3203e5..cd5702d6 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2121,6 +2121,21 @@ func (s *Service) ApiGetAccountCancellationListByMid(ctx *gin.Context, req *acco func (s *Service) ApiCreateZone(ctx *gin.Context, req *zoneproto.ApiCreateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneSrvOk + // 查询是否有空间(为避免之后重建索引,在这里控制唯一性) + list, err := _DefaultZone.OpListByMid(ctx, &zoneproto.OpListByMidReq{ + Uid: goproto.Int64(req.BaseRequest.Mid), + }) + if err != nil { + logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneSrvFail + return + } + if len(list) > 0 { + logger.Error("Zone of this mid exists, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneDuplicateKey + return + } + req.Zone.Mid = goproto.Int64(req.GetBaseRequest().Mid) req.Zone.ZoneMomentCount = goproto.Int64(0) req.Zone.ImageCount = goproto.Int64(0) @@ -2156,7 +2171,7 @@ func (s *Service) ApiCreateZone(ctx *gin.Context, req *zoneproto.ApiCreateReq) ( // 创建默认动态 cfg := apollostruct.ReferentialZoneMoment{} - err = apollo.GetJson(consts.ZoneKey, &cfg, apollo.ApolloOpts().SetNamespace("referential_zone_moment")) + err = apollo.GetJson(consts.ReferentialZoneMomentKey, &cfg, apollo.ApolloOpts().SetNamespace("zone")) if err != nil { logger.Error("Apollo read failed : %v", err) return errcode.ErrCodeApolloReadFail