service/app/mix/controller/zone_op.go

74 lines
1.7 KiB
Go
Raw Normal View History

2024-03-20 10:06:26 +08:00
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 OpCreateZone(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.OpCreateReq)
ec := service.DefaultService.OpCreateZone(ctx, req)
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("OpCreateZone fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}
func OpUpdateZone(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.OpUpdateReq)
ec := service.DefaultService.OpUpdateZone(ctx, req)
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("OpUpdateZone fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpDeleteZone(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.OpDeleteReq)
ec := service.DefaultService.OpDeleteZone(ctx, req.Id)
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("OpDeleteZone fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpGetZoneList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.OpListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.OpGetZoneList(ctx, req)
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("OpGetZoneList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &zoneproto.OpListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}