161 lines
3.9 KiB
Go
161 lines
3.9 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 ApiCreateMoment(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*momentproto.ApiCreateReq)
|
|
ec := service.DefaultService.ApiCreateMoment(ctx, req)
|
|
if ec != errcode.ErrCodeMomentSrvOk {
|
|
logger.Error("ApiCreateMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
ReplyOk(ctx, nil)
|
|
}
|
|
|
|
func ApiUpdateMoment(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*momentproto.ApiUpdateReq)
|
|
ec := service.DefaultService.ApiUpdateMoment(ctx, req)
|
|
if ec != errcode.ErrCodeMomentSrvOk {
|
|
logger.Error("ApiUpdateMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
ReplyOk(ctx, nil)
|
|
}
|
|
|
|
func ApiDeleteMoment(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*momentproto.ApiDeleteReq)
|
|
ec := service.DefaultService.ApiDeleteMoment(ctx, util.DerefInt64(req.Id))
|
|
if ec != errcode.ErrCodeMomentSrvOk {
|
|
logger.Error("ApiDeleteMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
ReplyOk(ctx, nil)
|
|
}
|
|
|
|
func ApiGetMomentList(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*momentproto.ApiListReq)
|
|
|
|
//设置默认页长
|
|
if req.Limit == 0 {
|
|
req.Limit = consts.DefaultPageSize
|
|
}
|
|
|
|
list, ec := service.DefaultService.ApiGetMomentList(ctx, req)
|
|
if ec != errcode.ErrCodeMomentSrvOk {
|
|
logger.Error("ApiGetMomentList 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.ApiListData{
|
|
List: list,
|
|
Offset: req.Offset + len(list),
|
|
}
|
|
if len(list) >= req.Limit {
|
|
data.More = 1
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func ApiGetMomentListByMid(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*momentproto.ApiListByMidReq)
|
|
|
|
//设置默认页长
|
|
if req.Limit == 0 {
|
|
req.Limit = consts.DefaultPageSize
|
|
}
|
|
|
|
list, ec := service.DefaultService.ApiGetMomentListByMid(ctx, req)
|
|
if ec != errcode.ErrCodeMomentSrvOk {
|
|
logger.Error("ApiGetMomentListByMid 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.ApiListData{
|
|
List: list,
|
|
Offset: req.Offset + len(list),
|
|
}
|
|
if len(list) >= req.Limit {
|
|
data.More = 1
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func ApiGetMomentListByMids(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*momentproto.ApiListByMidsReq)
|
|
|
|
//设置默认页长
|
|
if req.Limit == 0 {
|
|
req.Limit = consts.DefaultPageSize
|
|
}
|
|
|
|
list, ec := service.DefaultService.ApiGetMomentListByMids(ctx, req)
|
|
if ec != errcode.ErrCodeMomentSrvOk {
|
|
logger.Error("ApiGetMomentListByMids 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.ApiListData{
|
|
List: list,
|
|
Offset: req.Offset + len(list),
|
|
}
|
|
if len(list) >= req.Limit {
|
|
data.More = 1
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func ApiThumbsUpMoment(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*momentproto.ApiThumbsUpReq)
|
|
ec := service.DefaultService.ApiThumbsUpMoment(ctx, req)
|
|
if ec != errcode.ErrCodeMomentSrvOk {
|
|
logger.Error("ApiThumbsUpMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
ReplyOk(ctx, nil)
|
|
}
|