pusher/biz/handler/push/push_service.go
timerzz 4ec0cd1564
Some checks failed
Build image / build (push) Failing after 4m48s
feat 测试
2024-05-20 17:57:25 +08:00

89 lines
1.9 KiB
Go

// Code generated by hertz generator.
package push
import (
"context"
"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"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
)
// 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)
}