service/app/mix/controller/banner_op.go

66 lines
1.7 KiB
Go
Raw Permalink Normal View History

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