78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package swagger
|
|
|
|
import (
|
|
"github.com/labstack/echo/v4"
|
|
"penahub.gitlab.yandexcloud.net/external/treasurer/internal/errors"
|
|
)
|
|
|
|
//go:generate oapi-codegen --config api.yaml ../../../openapi.yaml
|
|
//go:generate oapi-codegen --config models.yaml ../../../openapi.yaml
|
|
|
|
type commonController interface {
|
|
// (GET /available)
|
|
GetAvailablePayments(ctx echo.Context) error
|
|
}
|
|
|
|
type yandexStatusController interface {
|
|
// (POST /yandex/payment/status/canceled)
|
|
SetPaymentStatusCanceled(ctx echo.Context) error
|
|
|
|
// (POST /yandex/payment/status/succeeded)
|
|
SetPaymentStatusSucceeded(ctx echo.Context) error
|
|
|
|
// (POST /yandex/payment/status/waiting)
|
|
SetPaymentStatusWaiting(ctx echo.Context) error
|
|
|
|
// (POST /yandex/refund/status/succeeded)
|
|
SetRefundStatusSucceeded(ctx echo.Context) error
|
|
}
|
|
|
|
type Deps struct {
|
|
CommonController commonController
|
|
YandexStatusController yandexStatusController
|
|
}
|
|
|
|
type API struct {
|
|
commonController commonController
|
|
yandexStatusController yandexStatusController
|
|
}
|
|
|
|
func New(deps Deps) (*API, errors.Error) {
|
|
if deps.CommonController == nil {
|
|
return nil, errors.NewWithMessage("CommonController in nil on <NewSwaggerAPI>", errors.ErrInvalidArgs)
|
|
}
|
|
|
|
if deps.YandexStatusController == nil {
|
|
return nil, errors.NewWithMessage("YandexStatusController in nil on <NewSwaggerAPI>", errors.ErrInvalidArgs)
|
|
}
|
|
|
|
return &API{
|
|
commonController: deps.CommonController,
|
|
yandexStatusController: deps.YandexStatusController,
|
|
}, nil
|
|
}
|
|
|
|
// Common
|
|
|
|
func (receiver *API) GetAvailablePayments(ctx echo.Context) error {
|
|
return receiver.commonController.GetAvailablePayments(ctx)
|
|
}
|
|
|
|
// Status (Yandex)
|
|
|
|
func (receiver *API) SetYandexPaymentStatusCanceled(ctx echo.Context) error {
|
|
return receiver.yandexStatusController.SetPaymentStatusCanceled(ctx)
|
|
}
|
|
|
|
func (receiver *API) SetYandexPaymentStatusSucceeded(ctx echo.Context) error {
|
|
return receiver.yandexStatusController.SetPaymentStatusSucceeded(ctx)
|
|
}
|
|
|
|
func (receiver *API) SetYandexPaymentStatusWaiting(ctx echo.Context) error {
|
|
return receiver.yandexStatusController.SetPaymentStatusWaiting(ctx)
|
|
}
|
|
|
|
func (receiver *API) SetYandexRefundStatusSucceeded(ctx echo.Context) error {
|
|
return receiver.yandexStatusController.SetRefundStatusSucceeded(ctx)
|
|
}
|