service/vendor/app/mix/controller/moment_op.go

99 lines
2.4 KiB
Go

package controller
import (
"service/api/consts"
"service/api/errcode"
momentproto "service/api/proto/moment/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"service/library/mediafiller"
"github.com/gin-gonic/gin"
)
func OpCreateMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpCreateReq)
ec := service.DefaultService.OpCreateMoment(ctx, req)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("OpCreateMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}
func OpUpdateMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpUpdateReq)
ec := service.DefaultService.OpUpdateMoment(ctx, req)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("OpUpdateMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpDeleteMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpDeleteReq)
ec := service.DefaultService.OpDeleteMoment(ctx, req.Id)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("OpDeleteMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpGetMomentList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.OpGetMomentList(ctx, req)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("OpGetMomentList 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 := &momentproto.OpListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func OpThumbsUpMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpThumbsUpReq)
moment, ec := service.DefaultService.OpThumbsUpMoment(ctx, req)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("OpThumbsUpMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &momentproto.OpThumbsUpData{
Moment: moment,
}
ReplyOk(ctx, data)
}