package controller import ( "service/api/consts" "service/api/errcode" zoneproto "service/api/proto/zone/proto" "service/app/mix/service" "service/bizcommon/util" "service/library/logger" "github.com/gin-gonic/gin" ) func ApiCreateZone(ctx *gin.Context) { req := ctx.MustGet("client_req").(*zoneproto.ApiCreateReq) ec := service.DefaultService.ApiCreateZone(ctx, req) if ec != errcode.ErrCodeZoneSrvOk { logger.Error("ApiCreateZone fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrorMsg(ctx, "server error") return } ReplyOk(ctx, nil) } func ApiUpdateZone(ctx *gin.Context) { req := ctx.MustGet("client_req").(*zoneproto.ApiUpdateReq) ec := service.DefaultService.ApiUpdateZone(ctx, req) if ec != errcode.ErrCodeZoneSrvOk { logger.Error("ApiUpdateZone fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) } func ApiDeleteZone(ctx *gin.Context) { req := ctx.MustGet("client_req").(*zoneproto.ApiDeleteReq) ec := service.DefaultService.ApiDeleteZone(ctx, req.Id) if ec != errcode.ErrCodeZoneSrvOk { logger.Error("ApiDeleteZone fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) } func ApiGetZoneList(ctx *gin.Context) { req := ctx.MustGet("client_req").(*zoneproto.ApiListReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } list, ec := service.DefaultService.ApiGetZoneList(ctx, req) if ec != errcode.ErrCodeZoneSrvOk { logger.Error("ApiGetZoneList fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } data := &zoneproto.ApiListData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) }