62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/go-kratos/kratos/v3/errors"
|
|
"kra/internal/service/business"
|
|
"kra/internal/service/dto"
|
|
"net/http"
|
|
)
|
|
|
|
type Channel struct{ service *business.ChannelService }
|
|
|
|
func NewChannel(service *business.ChannelService) *Channel { return &Channel{service: service} }
|
|
func (h *Channel) List(c *gin.Context) {
|
|
var req dto.ChannelQuery
|
|
if c.ShouldBindQuery(&req) != nil {
|
|
Fail(c, "渠道查询参数不正确")
|
|
return
|
|
}
|
|
result, err := h.service.List(c.Request.Context(), &req)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, result)
|
|
}
|
|
func (h *Channel) Bindings(c *gin.Context) {
|
|
result, err := h.service.BindOptions(c.Request.Context(), c.Query("sourceDb"))
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, result)
|
|
}
|
|
func (h *Channel) Create(c *gin.Context) {
|
|
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 1<<20)
|
|
var req dto.ChannelCreateRequest
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
Fail(c, "渠道参数不正确")
|
|
return
|
|
}
|
|
result, err := h.service.Create(c.Request.Context(), &req)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
Write(c, CodeSuccess, result, "添加成功,数据同步到列表可能有延迟")
|
|
}
|
|
func (h *Channel) Games(c *gin.Context) {
|
|
var req dto.ChannelGameQuery
|
|
if c.ShouldBindQuery(&req) != nil {
|
|
Fail(c, "渠道查询参数不正确")
|
|
return
|
|
}
|
|
result, err := h.service.Games(c.Request.Context(), &req)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, result)
|
|
}
|