service/app/mix/controller/zonemoment_op.go

106 lines
2.8 KiB
Go

package controller
import (
"service/api/consts"
"service/api/errcode"
zonemomentproto "service/api/proto/zonemoment/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"service/library/mediafiller"
"github.com/gin-gonic/gin"
)
func OpCreateZoneMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.OpCreateReq)
ec := service.DefaultService.OpCreateZoneMoment(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("OpCreateZoneMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}
func OpUpdateZoneMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.OpUpdateReq)
ec := service.DefaultService.OpUpdateZoneMoment(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("OpUpdateZoneMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpDeleteZoneMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.OpDeleteReq)
ec := service.DefaultService.OpDeleteZoneMoment(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("OpDeleteZoneMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpGetZoneMomentList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.OpListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.OpGetZoneMomentList(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("OpGetZoneMomentList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
//填充媒体切片
mediaFillableList := make([]mediafiller.MediaFillable, len(list))
for i, media := range list {
mediaFillableList[i] = media.MediaComp
}
mediafiller.FillList(ctx, mediaFillableList)
data := &zonemomentproto.OpListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func OpReviewZoneMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.OpReviewReq)
ec := service.DefaultService.OpReviewZoneMoment(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("OpReviewZoneMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpHeadZoneMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.OpHeadReq)
ec := service.DefaultService.OpHeadZoneMoment(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("OpHeadZoneMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}