customer/internal/swagger/api.go

129 lines
3.4 KiB
Go
Raw Normal View History

2023-05-17 03:39:29 +00:00
package swagger
2023-05-17 20:27:09 +00:00
import (
2023-05-19 04:50:40 +00:00
"log"
2023-05-17 20:27:09 +00:00
"net/http"
"github.com/labstack/echo/v4"
)
2023-05-17 03:39:29 +00:00
//go:generate oapi-codegen --config api.yaml ../../openapi.yaml
//go:generate oapi-codegen --config models.yaml ../../openapi.yaml
2023-05-17 20:27:09 +00:00
2023-05-19 04:50:40 +00:00
type accountController interface {
2023-05-17 20:27:09 +00:00
RemoveAccount(ctx echo.Context) error
GetAccount(ctx echo.Context) error
CreateAccount(ctx echo.Context) error
RemoveDirectAccount(ctx echo.Context, userID string) error
GetDirectAccount(ctx echo.Context, userID string) error
2023-05-17 20:27:09 +00:00
GetAccounts(ctx echo.Context, params PaginationAccountsParams) error
}
2023-05-19 04:50:40 +00:00
type currencyController interface {
GetCurrencies(ctx echo.Context) error
PutCurrencies(ctx echo.Context) error
}
2023-05-17 20:27:09 +00:00
type Deps struct {
2023-05-19 04:50:40 +00:00
AccountController accountController
CurrencyController currencyController
2023-05-17 20:27:09 +00:00
}
type API struct {
2023-05-19 04:50:40 +00:00
AccountController accountController
CurrencyController currencyController
2023-05-17 20:27:09 +00:00
}
func New(deps *Deps) *API {
2023-05-19 04:50:40 +00:00
if deps == nil {
log.Panicln("deps is nil on <New (API)>")
}
if deps.AccountController == nil {
log.Panicln("AccountController is nil on <New (API)>")
}
if deps.CurrencyController == nil {
log.Panicln("CurrencyController is nil on <New (API)>")
}
2023-05-17 20:27:09 +00:00
return &API{
2023-05-19 04:50:40 +00:00
AccountController: deps.AccountController,
CurrencyController: deps.CurrencyController,
2023-05-17 20:27:09 +00:00
}
}
2023-05-19 04:50:40 +00:00
// Account
2023-05-17 20:27:09 +00:00
func (receiver *API) DeleteAccount(ctx echo.Context) error {
return receiver.AccountController.RemoveAccount(ctx)
2023-05-17 20:27:09 +00:00
}
func (receiver *API) GetAccount(ctx echo.Context) error {
return receiver.AccountController.GetAccount(ctx)
2023-05-17 20:27:09 +00:00
}
func (receiver *API) AddAccount(ctx echo.Context) error {
return receiver.AccountController.CreateAccount(ctx)
2023-05-17 20:27:09 +00:00
}
func (receiver *API) DeleteDirectAccount(ctx echo.Context, userID string) error {
return receiver.AccountController.RemoveDirectAccount(ctx, userID)
2023-05-17 20:27:09 +00:00
}
func (receiver *API) GetDirectAccount(ctx echo.Context, userID string) error {
return receiver.AccountController.GetDirectAccount(ctx, userID)
2023-05-17 20:27:09 +00:00
}
func (receiver *API) PaginationAccounts(ctx echo.Context, params PaginationAccountsParams) error {
return receiver.AccountController.GetAccounts(ctx, params)
2023-05-17 20:27:09 +00:00
}
2023-05-19 04:50:40 +00:00
// Cart
func (receiver *API) RemoveFromCart(ctx echo.Context, _ RemoveFromCartParams) error {
2023-05-17 20:27:09 +00:00
return ctx.String(http.StatusNotImplemented, "method not implemented")
}
func (receiver *API) Add2cart(ctx echo.Context) error {
return ctx.String(http.StatusNotImplemented, "method not implemented")
}
func (receiver *API) PayCart(ctx echo.Context) error {
return ctx.String(http.StatusNotImplemented, "method not implemented")
}
2023-05-19 04:50:40 +00:00
// Currency
2023-05-17 20:27:09 +00:00
func (receiver *API) GetCurrencies(ctx echo.Context) error {
2023-05-19 05:21:52 +00:00
return receiver.CurrencyController.GetCurrencies(ctx)
2023-05-17 20:27:09 +00:00
}
func (receiver *API) UpdateCurrencies(ctx echo.Context) error {
2023-05-19 05:21:52 +00:00
return receiver.CurrencyController.PutCurrencies(ctx)
2023-05-17 20:27:09 +00:00
}
2023-05-19 04:50:40 +00:00
// History
func (receiver *API) GetHistory(ctx echo.Context, _ GetHistoryParams) error {
2023-05-17 20:27:09 +00:00
return ctx.String(http.StatusNotImplemented, "method not implemented")
}
func (receiver *API) Add2history(ctx echo.Context) error {
return ctx.String(http.StatusNotImplemented, "method not implemented")
}
2023-05-19 04:50:40 +00:00
// Wallet
func (receiver *API) RequestMoney(ctx echo.Context, _ RequestMoneyParams) error {
2023-05-17 20:27:09 +00:00
return ctx.String(http.StatusNotImplemented, "method not implemented")
}
func (receiver *API) ChangeCurrency(ctx echo.Context) error {
return ctx.String(http.StatusNotImplemented, "method not implemented")
}
func (receiver *API) PutMoney(ctx echo.Context) error {
return ctx.String(http.StatusNotImplemented, "method not implemented")
}