66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package controller
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"service/api/errcode"
|
|
catalogproto "service/api/proto/catalog/proto"
|
|
"service/app/mix/service"
|
|
"service/bizcommon/util"
|
|
"service/library/logger"
|
|
)
|
|
|
|
func OpCreateCatalog(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*catalogproto.OpCreateReq)
|
|
ec := service.DefaultService.OpCreateCatalog(ctx, req)
|
|
if ec != errcode.ErrCodeCatalogSrvOk {
|
|
logger.Error("OpCreateCatalog fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrorMsg(ctx, "server error")
|
|
return
|
|
}
|
|
|
|
ReplyOk(ctx, nil)
|
|
}
|
|
|
|
func OpUpdateCatalog(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*catalogproto.OpUpdateReq)
|
|
ec := service.DefaultService.OpUpdateCatalog(ctx, req)
|
|
if ec != errcode.ErrCodeCatalogSrvOk {
|
|
logger.Error("OpUpdateCatalog fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
ReplyOk(ctx, nil)
|
|
}
|
|
|
|
func OpDeleteCatalog(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*catalogproto.OpDeleteReq)
|
|
ec := service.DefaultService.OpDeleteCatalog(ctx, req.Id)
|
|
if ec != errcode.ErrCodeCatalogSrvOk {
|
|
logger.Error("OpDeleteCatalog fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
ReplyOk(ctx, nil)
|
|
}
|
|
|
|
func OpGetCatalogList(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*catalogproto.OpListReq)
|
|
list, ec := service.DefaultService.OpGetCatalogList(ctx, req)
|
|
if ec != errcode.ErrCodeCatalogSrvOk {
|
|
logger.Error("OpGetCatalogList fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
data := &catalogproto.OpListData{
|
|
List: list,
|
|
Offset: req.Offset + len(list),
|
|
}
|
|
if len(list) >= req.Limit {
|
|
data.More = 1
|
|
}
|
|
ReplyOk(ctx, data)
|
|
}
|