service/app/mix/controller/moment_op.go

198 lines
4.8 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)
ReplyErrCodeMsg(ctx, ec)
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)
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 OpGetDeletedMomentList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.OpGetDeletedMomentList(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 OpGetMomentListByMid(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpListByMidReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.OpGetMomentListByMid(ctx, req)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("OpGetMomentListByMid 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 OpGetMomentListByIds(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpListByIdsReq)
list, ec := service.DefaultService.OpGetMomentListByIds(ctx, req)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("OpGetMomentListByIds 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,
}
ReplyOk(ctx, data)
}
func OpThumbsUpMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpThumbsUpReq)
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
}
ReplyOk(ctx, nil)
}
func OpReviewMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*momentproto.OpReviewReq)
ec := service.DefaultService.OpReviewMoment(ctx, req)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("OpReviewMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}