service/app/mix/controller/zone_collaborator_api.go

86 lines
2.5 KiB
Go
Raw Normal View History

2024-04-08 20:05:13 +08:00
package controller
import (
"service/api/consts"
"service/api/errcode"
zone_collaborator_proto "service/api/proto/zone_collaborator/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"service/library/mediafiller"
"github.com/gin-gonic/gin"
)
func ApiCreateZoneCollaborator(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zone_collaborator_proto.ApiCreateReq)
ec := service.DefaultService.ApiCreateZoneCollaborator(ctx, req)
if ec != errcode.ErrCodeZoneCollaboratorSrvOk {
logger.Error("ApiCreateZoneCollaborator fail, req: %v, ec: %v", util.ToJson(req), ec)
2024-04-22 18:19:37 +08:00
ReplyErrCodeMsg(ctx, ec)
2024-04-08 20:05:13 +08:00
return
}
ReplyOk(ctx, nil)
}
func ApiUpdateZoneCollaborator(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zone_collaborator_proto.ApiUpdateReq)
ec := service.DefaultService.ApiUpdateZoneCollaborator(ctx, req)
if ec != errcode.ErrCodeZoneCollaboratorSrvOk {
logger.Error("ApiUpdateZoneCollaborator fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiDeleteZoneCollaborator(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zone_collaborator_proto.ApiDeleteReq)
ec := service.DefaultService.ApiDeleteZoneCollaborator(ctx, util.DerefInt64(req.Id))
if ec != errcode.ErrCodeZoneCollaboratorSrvOk {
logger.Error("ApiDeleteZoneCollaborator fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiGetZoneCollaboratorList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zone_collaborator_proto.ApiListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
2024-04-22 18:19:37 +08:00
list, ztpVO, ec := service.DefaultService.ApiGetZoneCollaboratorList(ctx, req)
2024-04-08 20:05:13 +08:00
if ec != errcode.ErrCodeZoneCollaboratorSrvOk {
logger.Error("ApiGetZoneCollaboratorList 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.Account.Avatar
}
mediafiller.FillList(ctx, mediaFillableList)
2024-04-22 18:56:53 +08:00
if ztpVO != nil && ztpVO.Account != nil && ztpVO.Account.Avatar != nil {
mediafiller.FillEntity(ctx, ztpVO.Account.Avatar)
}
2024-04-08 20:05:13 +08:00
data := &zone_collaborator_proto.ApiListData{
2024-04-22 18:19:37 +08:00
List: list,
ZoneThirdPartnerVO: ztpVO,
Offset: req.Offset + len(list),
2024-04-08 20:05:13 +08:00
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}