service/app/mix/controller/zonemoment_op.go

150 lines
4.0 KiB
Go
Raw Permalink Normal View History

2024-03-21 23:26:23 +08:00
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"
2024-04-03 06:19:11 +08:00
"service/library/mediafiller"
2024-03-21 23:26:23 +08:00
"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)
2024-04-04 20:48:42 +08:00
ec := service.DefaultService.OpDeleteZoneMoment(ctx, req)
2024-03-21 23:26:23 +08:00
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
}
2024-04-03 06:19:11 +08:00
//填充媒体切片
mediaFillableList := make([]mediafiller.MediaFillable, len(list))
for i, media := range list {
mediaFillableList[i] = media.MediaComp
}
mediafiller.FillList(ctx, mediaFillableList)
2024-03-21 23:26:23 +08:00
data := &zonemomentproto.OpListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
2024-04-02 22:47:41 +08:00
2024-04-30 09:22:18 +08:00
func OpGetZoneMomentListByUserId(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.OpListByUserIdReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.OpGetZoneMomentListByUserId(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("OpGetZoneMomentListByUserId 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.OpListByUserIdData{
ListByUserId: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
2024-04-02 22:47:41 +08:00
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)
}
2024-04-11 00:25:06 +08:00
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)
}
2024-05-01 02:51:47 +08:00
func OpSetPrivateZoneMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.OpSetPrivateReq)
ec := service.DefaultService.OpSetPrivateZoneMoment(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("OpSetPrivateZoneMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}