service/app/mix/controller/zone_api.go

184 lines
5.3 KiB
Go
Raw Normal View History

2024-03-20 10:06:26 +08:00
package controller
import (
"service/api/consts"
"service/api/errcode"
zoneproto "service/api/proto/zone/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
2024-04-05 19:23:36 +08:00
"service/library/mediafiller"
2024-03-20 10:06:26 +08:00
"github.com/gin-gonic/gin"
)
func ApiCreateZone(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.ApiCreateReq)
ec := service.DefaultService.ApiCreateZone(ctx, req)
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("ApiCreateZone fail, req: %v, ec: %v", util.ToJson(req), ec)
2024-04-27 19:48:57 +08:00
ReplyErrCodeMsg(ctx, ec)
2024-03-20 10:06:26 +08:00
return
}
ReplyOk(ctx, nil)
}
func ApiUpdateZone(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.ApiUpdateReq)
ec := service.DefaultService.ApiUpdateZone(ctx, req)
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("ApiUpdateZone fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiDeleteZone(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.ApiDeleteReq)
ec := service.DefaultService.ApiDeleteZone(ctx, req.Id)
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("ApiDeleteZone fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiGetZoneList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.ApiListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetZoneList(ctx, req)
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("ApiGetZoneList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &zoneproto.ApiListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
2024-04-04 20:48:42 +08:00
func ApiGetZoneListByVisitorMid(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.ApiListByVisitorMidReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetZoneListByVisitorMid(ctx, req)
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("ApiGetZoneList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
2024-04-05 19:23:36 +08:00
objectMediaNum := 5 // 单个空间服务总共5个媒体类
mediaFillableList := make([]mediafiller.MediaFillable, len(list)*objectMediaNum)
for i, vo := range list {
mediaFillableList[objectMediaNum*i+0] = vo.Previews
mediaFillableList[objectMediaNum*i+1] = vo.StreamerExt.Cover
mediaFillableList[objectMediaNum*i+2] = vo.StreamerExt.Shorts
mediaFillableList[objectMediaNum*i+3] = vo.StreamerExt.Album
mediaFillableList[objectMediaNum*i+4] = vo.StreamerExt.Avatar
}
mediafiller.FillList(ctx, mediaFillableList)
2024-04-04 20:48:42 +08:00
data := &zoneproto.ApiListByVisitorMidData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func ApiGetZoneListByMid(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.ApiListByMidReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
2024-04-18 22:53:25 +08:00
refundEnable, refundStatus, list, ec := service.DefaultService.ApiGetZoneListByMid(ctx, req)
2024-04-04 20:48:42 +08:00
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("ApiGetZoneListByMid fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
2024-04-05 19:23:36 +08:00
objectMediaNum := 5 // 单个空间服务总共5个媒体类
mediaFillableList := make([]mediafiller.MediaFillable, len(list)*objectMediaNum)
for i, vo := range list {
mediaFillableList[objectMediaNum*i+0] = vo.Previews
mediaFillableList[objectMediaNum*i+1] = vo.StreamerExt.Cover
mediaFillableList[objectMediaNum*i+2] = vo.StreamerExt.Shorts
mediaFillableList[objectMediaNum*i+3] = vo.StreamerExt.Album
mediaFillableList[objectMediaNum*i+4] = vo.StreamerExt.Avatar
}
mediafiller.FillList(ctx, mediaFillableList)
2024-04-04 20:48:42 +08:00
data := &zoneproto.ApiListByMidData{
2024-04-18 22:53:25 +08:00
List: list,
Offset: req.Offset + len(list),
RefundEnable: refundEnable,
RefundStatus: refundStatus,
2024-04-04 20:48:42 +08:00
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
2024-04-12 06:40:30 +08:00
func ApiGetZoneListByUserIdFromOutside(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.ApiListByUserIdFromOutsideReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
2024-04-18 20:27:18 +08:00
refundEnable, refundStatus, list, ec := service.DefaultService.ApiGetZoneListByUserIdFromOutside(ctx, req)
2024-04-12 06:40:30 +08:00
if ec != errcode.ErrCodeZoneSrvOk {
logger.Error("ApiGetZoneListByUserIdFromOutside fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
objectMediaNum := 5 // 单个空间服务总共5个媒体类
mediaFillableList := make([]mediafiller.MediaFillable, len(list)*objectMediaNum)
for i, vo := range list {
mediaFillableList[objectMediaNum*i+0] = vo.Previews
mediaFillableList[objectMediaNum*i+1] = vo.StreamerExt.Cover
mediaFillableList[objectMediaNum*i+2] = vo.StreamerExt.Shorts
mediaFillableList[objectMediaNum*i+3] = vo.StreamerExt.Album
mediaFillableList[objectMediaNum*i+4] = vo.StreamerExt.Avatar
}
mediafiller.FillList(ctx, mediaFillableList)
data := &zoneproto.ApiListByMidData{
2024-04-16 21:13:26 +08:00
List: list,
Offset: req.Offset + len(list),
RefundEnable: refundEnable,
2024-04-18 20:27:18 +08:00
RefundStatus: refundStatus,
2024-04-12 06:40:30 +08:00
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}