service/app/mix/controller/moment_op.go

95 lines
2.3 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
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)
2024-01-13 00:32:19 +08:00
ReplyErrCodeMsg(ctx, ec)
2023-12-21 22:17:40 +08:00
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)
2024-01-27 02:04:17 +08:00
ec := service.DefaultService.OpDeleteMoment(ctx, req)
2023-12-21 22:17:40 +08:00
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)
2024-01-13 00:32:19 +08:00
ec := service.DefaultService.OpThumbsUpMoment(ctx, req)
2023-12-21 22:17:40 +08:00
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("OpThumbsUpMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
2024-01-13 00:32:19 +08:00
ReplyOk(ctx, nil)
2023-12-21 22:17:40 +08:00
}