2024-05-17 18:02:10 +08:00
|
|
|
// Code generated by hertz generator.
|
|
|
|
|
|
|
|
package push
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-05-20 17:57:25 +08:00
|
|
|
"gitea.timerzz.com/kedaya_haitao/pusher/biz/service"
|
|
|
|
config "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config"
|
|
|
|
push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push"
|
2024-05-17 18:02:10 +08:00
|
|
|
"github.com/cloudwego/hertz/pkg/app"
|
|
|
|
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
|
|
|
)
|
2024-05-20 17:57:25 +08:00
|
|
|
|
|
|
|
// Push .
|
|
|
|
// @router /api/v1/push [POST]
|
|
|
|
func Push(ctx context.Context, c *app.RequestContext) {
|
|
|
|
var err error
|
|
|
|
var req push.PushReq
|
|
|
|
err = c.BindAndValidate(&req)
|
|
|
|
if err != nil {
|
|
|
|
c.String(consts.StatusBadRequest, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := service.NewPushService(ctx).Run(&req)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
c.String(consts.StatusBadRequest, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(consts.StatusOK, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add .
|
|
|
|
// @router /api/v1/pushers [POST]
|
|
|
|
func Add(ctx context.Context, c *app.RequestContext) {
|
|
|
|
var err error
|
|
|
|
var req config.PusherConfig
|
|
|
|
err = c.BindAndValidate(&req)
|
|
|
|
if err != nil {
|
|
|
|
c.String(consts.StatusBadRequest, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := new(push.Resp)
|
|
|
|
|
|
|
|
resp, err = service.NewAddService(ctx).Run(&req)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
c.String(consts.StatusBadRequest, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.JSON(consts.StatusOK, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// List .
|
|
|
|
// @router /api/v1/pushers [GET]
|
|
|
|
func List(ctx context.Context, c *app.RequestContext) {
|
|
|
|
var err error
|
|
|
|
var req push.ListPusherRequest
|
|
|
|
err = c.BindAndValidate(&req)
|
|
|
|
if err != nil {
|
|
|
|
c.String(consts.StatusBadRequest, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp *push.ListPusherResponse
|
|
|
|
resp, err = service.NewListService(ctx).Run(&req)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
c.String(consts.StatusBadRequest, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.JSON(consts.StatusOK, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetPusherOptions .
|
|
|
|
// @router /api/v1/pushers/options [GET]
|
|
|
|
func GetPusherOptions(ctx context.Context, c *app.RequestContext) {
|
|
|
|
resp, err := service.NewGetPusherOptionsService(ctx).Run()
|
|
|
|
if err != nil {
|
|
|
|
c.String(consts.StatusBadRequest, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(consts.StatusOK, resp)
|
|
|
|
}
|