service/app/mix/controller/product_op.go

67 lines
1.7 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package controller
import (
"service/api/errcode"
productproto "service/api/proto/product/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"github.com/gin-gonic/gin"
)
func OpCreateProduct(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*productproto.OpCreateReq)
ec := service.DefaultService.OpCreateProduct(ctx, req)
if ec != errcode.ErrCodeProductSrvOk {
logger.Error("OpCreateProduct fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}
func OpUpdateProduct(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*productproto.OpUpdateReq)
ec := service.DefaultService.OpUpdateProduct(ctx, req)
if ec != errcode.ErrCodeProductSrvOk {
logger.Error("OpUpdateProduct fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpDeleteProduct(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*productproto.OpDeleteReq)
ec := service.DefaultService.OpDeleteProduct(ctx, req.Id)
if ec != errcode.ErrCodeProductSrvOk {
logger.Error("OpUpdateProduct fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpGetProductList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*productproto.OpListReq)
list, ec := service.DefaultService.OpGetProductList(ctx, req)
if ec != errcode.ErrCodeProductSrvOk {
logger.Error("OpGetProductList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &productproto.OpListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}