service/app/mix/controller/zone_collaborator_api.go

82 lines
2.3 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)
ReplyErrorMsg(ctx, "server error")
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
}
list, ec := service.DefaultService.ApiGetZoneCollaboratorList(ctx, req)
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)
data := &zone_collaborator_proto.ApiListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}