service/app/mix/controller/streamerlink_api.go

98 lines
2.7 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package controller
import (
"service/api/consts"
"service/api/errcode"
streamerlinkproto "service/api/proto/streamerlink/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"github.com/gin-gonic/gin"
)
func ApiCreateStreamerLink(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*streamerlinkproto.ApiCreateReq)
ec := service.DefaultService.ApiCreateStreamerLink(ctx, req)
if ec != errcode.ErrCodeStreamerLinkSrvOk {
logger.Error("OpCreateStreamerLink fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}
func ApiUpdateStreamerLink(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*streamerlinkproto.ApiUpdateReq)
ec := service.DefaultService.ApiUpdateStreamerLink(ctx, req)
if ec != errcode.ErrCodeStreamerLinkSrvOk {
logger.Error("OpUpdateStreamerLink fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiDeleteStreamerLink(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*streamerlinkproto.ApiDeleteReq)
ec := service.DefaultService.ApiDeleteStreamerLink(ctx, util.DerefInt64(req.Id))
if ec != errcode.ErrCodeStreamerLinkSrvOk {
logger.Error("OpDeleteStreamerLink fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiGetStreamerLinkListByMid(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*streamerlinkproto.ApiListByMidReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetStreamerLinkListByMid(ctx, req)
if ec != errcode.ErrCodeStreamerLinkSrvOk {
logger.Error("OpGetStreamerLinkListByMid fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &streamerlinkproto.ApiListByMidData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func ApiCreateBatchStreamerLink(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*streamerlinkproto.ApiCreateBatchReq)
ec := service.DefaultService.ApiCreateBatchStreamerLink(ctx, req)
if ec != errcode.ErrCodeStreamerLinkSrvOk {
logger.Error("OpCreateBatchStreamerLink fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}
func ApiDeleteBatchStreamerLink(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*streamerlinkproto.ApiDeleteBatchReq)
ec := service.DefaultService.ApiDeleteBatchStreamerLink(ctx, req)
if ec != errcode.ErrCodeStreamerLinkSrvOk {
logger.Error("OpDeleteBatchStreamerLink fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}