package controller import ( "service/api/consts" "service/api/errcode" streamerproto "service/api/proto/streamer/proto" "service/app/mix/service" "service/bizcommon/util" "service/library/logger" "service/library/mediafiller" "github.com/gin-gonic/gin" ) func OpCreateStreamer(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpCreateReq) ec := service.DefaultService.OpCreateStreamer(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpCreateStreamer fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrorMsg(ctx, "server error") return } ReplyOk(ctx, nil) } func OpUpdateStreamer(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpUpdateReq) ec := service.DefaultService.OpUpdateStreamer(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpUpdateStreamer fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) } func OpDeleteStreamer(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpDeleteReq) ec := service.DefaultService.OpDeleteStreamer(ctx, req.Id) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpDeleteStreamer fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) } func OpGetStreamerListByMid(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpListByMidReq) streamer, ec := service.DefaultService.OpGetStreamerListByMid(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpGetStreamerList fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体切片 mediaFillableList := make([]mediafiller.MediaFillable, 3) mediaFillableList[0] = streamer.Cover mediaFillableList[1] = streamer.Shorts mediaFillableList[2] = streamer.Album mediafiller.FillList(ctx, mediaFillableList) data := &streamerproto.OpListByMidData{ Streamer: streamer, } ReplyOk(ctx, data) } func OpGetStreamerExtListByMid(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpListExtByMidReq) streamerExt, ec := service.DefaultService.OpGetStreamerExtListByMid(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpGetStreamerExtListByMid fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体切片 mediaFillableList := make([]mediafiller.MediaFillable, 4) mediaFillableList[0] = streamerExt.Avatar mediaFillableList[1] = streamerExt.Cover mediaFillableList[2] = streamerExt.Shorts mediaFillableList[3] = streamerExt.Album mediafiller.FillList(ctx, mediaFillableList) data := &streamerproto.OpListExtByMidData{ StreamerExt: streamerExt, } ReplyOk(ctx, data) } func OpGetStreamerExtListByMids(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpListExtByMidsReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } list, ec := service.DefaultService.OpGetStreamerExtListByMids(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpGetStreamerExtListByMids fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体切片 objectMediaNum := 4 // 单个主播服务总共4个媒体类 mediaFillableList := make([]mediafiller.MediaFillable, len(list)*objectMediaNum) for i, vo := range list { mediaFillableList[objectMediaNum*i+0] = vo.Avatar mediaFillableList[objectMediaNum*i+1] = vo.Cover mediaFillableList[objectMediaNum*i+2] = vo.Shorts mediaFillableList[objectMediaNum*i+3] = vo.Album } mediafiller.FillList(ctx, mediaFillableList) data := &streamerproto.OpListExtByMidsData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) } func OpGetStreamerExtListByUserId(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpListExtByUserIdReq) streamerExt, ec := service.DefaultService.OpGetStreamerExtListByUserId(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpGetStreamerExtListByUserId fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体切片 mediaFillableList := make([]mediafiller.MediaFillable, 4) mediaFillableList[0] = streamerExt.Avatar mediaFillableList[1] = streamerExt.Cover mediaFillableList[2] = streamerExt.Shorts mediaFillableList[3] = streamerExt.Album mediafiller.FillList(ctx, mediaFillableList) data := &streamerproto.OpListExtByUserIdData{ StreamerExt: streamerExt, } ReplyOk(ctx, data) } func OpGetStreamerExtListFuzzilyByUserId(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpListExtFuzzilyByUserIdReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } list, ec := service.DefaultService.OpGetStreamerExtListFuzzilyByUserId(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpGetStreamerExtListFuzzilyByUserId fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体切片 objectMediaNum := 4 // 单个主播服务总共4个媒体类 mediaFillableList := make([]mediafiller.MediaFillable, len(list)*objectMediaNum) for i, vo := range list { mediaFillableList[objectMediaNum*i+0] = vo.Avatar mediaFillableList[objectMediaNum*i+1] = vo.Cover mediaFillableList[objectMediaNum*i+2] = vo.Shorts mediaFillableList[objectMediaNum*i+3] = vo.Album } mediafiller.FillList(ctx, mediaFillableList) data := &streamerproto.OpListExtFuzzilyByUserIdData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) } func OpGetStreamerExtListFuzzilyByName(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpListExtFuzzilyByNameReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } list, ec := service.DefaultService.OpGetStreamerExtListFuzzilyByName(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpGetStreamerExtListFuzzilyByName fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体切片 objectMediaNum := 4 // 单个主播服务总共4个媒体类 mediaFillableList := make([]mediafiller.MediaFillable, len(list)*objectMediaNum) for i, vo := range list { mediaFillableList[objectMediaNum*i+0] = vo.Avatar mediaFillableList[objectMediaNum*i+1] = vo.Cover mediaFillableList[objectMediaNum*i+2] = vo.Shorts mediaFillableList[objectMediaNum*i+3] = vo.Album } mediafiller.FillList(ctx, mediaFillableList) data := &streamerproto.OpListExtFuzzilyByUserIdData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) } func OpGetStreamerWxId(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpListStreamerWxIdReq) wxIdVO, ec := service.DefaultService.OpGetStreamerWxId(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpGetStreamerWxId fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } data := &streamerproto.OpListStreamerWxIdData{ WxIdVO: wxIdVO, } ReplyOk(ctx, data) } func OpGetStreamerRecommList(ctx *gin.Context) { req := ctx.MustGet("client_req").(*streamerproto.OpRecommListReq) list, ec := service.DefaultService.OpGetStreamerRecommList(ctx, req) if ec != errcode.ErrCodeStreamerSrvOk { logger.Error("OpGetStreamerRecommList fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } data := &streamerproto.OpRecommListData{ RecommList: list, } ReplyOk(ctx, data) }