2023-11-05 13:58:41 +00:00
|
|
|
package swagger
|
|
|
|
|
|
|
|
import (
|
2023-11-06 08:30:41 +00:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
2023-11-05 13:58:41 +00:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
"go.uber.org/zap"
|
2023-11-06 08:30:41 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
2023-11-05 13:58:41 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/repository"
|
2023-11-06 08:30:41 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/echotools"
|
2023-11-05 13:58:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type API2 struct {
|
2023-11-06 07:27:06 +00:00
|
|
|
logger *zap.Logger
|
|
|
|
history repository.HistoryRepository
|
|
|
|
account repository.AccountRepository
|
|
|
|
currency repository.CurrencyRepository
|
|
|
|
// cart repository.CartRepository
|
|
|
|
// wallet repository.WalletRepository
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ ServerInterface = (*API2)(nil)
|
|
|
|
|
|
|
|
func NewAPI2(logger *zap.Logger, db *mongo.Database) API2 {
|
|
|
|
return API2{
|
2023-11-06 07:27:06 +00:00
|
|
|
logger: logger,
|
|
|
|
history: repository.NewHistoryRepository2(logger, db.Collection("histories")),
|
|
|
|
currency: repository.NewCurrencyRepository2(logger, db.Collection("currency_lists")),
|
|
|
|
account: repository.NewAccountRepository2(logger, db.Collection("accounts")),
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
// Health
|
|
|
|
|
|
|
|
func (api *API2) GetHealth(ctx echo.Context) error {
|
|
|
|
return ctx.String(http.StatusOK, "OK")
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
// Account
|
|
|
|
|
|
|
|
func (api *API2) DeleteAccount(ctx echo.Context) error {
|
2023-11-06 09:31:39 +00:00
|
|
|
userID, ok := ctx.Get(models.AuthJWTDecodedUserIDKey).(string)
|
|
|
|
if !ok {
|
|
|
|
api.logger.Error("failed to convert jwt payload to string on <RemoveAccount> of <AccountController>")
|
|
|
|
|
|
|
|
return errors.HTTP(ctx, errors.New(
|
|
|
|
fmt.Errorf("failed to convert jwt payload to string: %s", userID),
|
|
|
|
errors.ErrInvalidArgs,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
account, err := api.account.Remove(ctx.Request().Context(), userID)
|
|
|
|
if err != nil {
|
|
|
|
api.logger.Error("failed to remove account on <RemoveAccount> of <AccountService>",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.String("userID", userID),
|
|
|
|
)
|
|
|
|
return errors.HTTP(ctx, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.JSON(http.StatusOK, account)
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API2) ChangeAccount(ctx echo.Context) error {
|
2023-11-06 08:30:41 +00:00
|
|
|
userID, ok := ctx.Get(models.AuthJWTDecodedUserIDKey).(string)
|
|
|
|
if !ok {
|
|
|
|
api.logger.Error("failed to convert jwt payload to string on <UpdateAccountName> of <AccountController>")
|
|
|
|
return errors.HTTP(ctx, errors.New(fmt.Errorf("failed to convert jwt payload to string: %s", userID), errors.ErrInvalidArgs))
|
|
|
|
}
|
|
|
|
|
|
|
|
request, bindErr := echotools.Bind[models.Name](ctx)
|
|
|
|
if bindErr != nil {
|
|
|
|
api.logger.Error("failed to bind json request on <UpdateAccountName> of <AccountController>", zap.Error(bindErr))
|
|
|
|
return errors.HTTP(ctx, errors.New(fmt.Errorf("failed to bind json: %w", bindErr), errors.ErrInternalError))
|
|
|
|
}
|
|
|
|
|
|
|
|
account, err := api.account.UpdateName(ctx.Request().Context(), userID, request)
|
|
|
|
if err != nil {
|
|
|
|
api.logger.Error("failed to update account name on <UpdateAccountName> of <AccountService>", zap.Error(err))
|
|
|
|
return errors.HTTP(ctx, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.JSON(http.StatusOK, account)
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
func (api *API2) SetAccountVerificationStatus(ctx echo.Context, userID string) error {
|
|
|
|
request, bindErr := echotools.Bind[models.SetAccountStatus](ctx)
|
|
|
|
if bindErr != nil {
|
|
|
|
api.logger.Error("failed to bind json request on <SetVerificationStatus> of <AccountController>", zap.Error(bindErr))
|
|
|
|
return errors.HTTP(ctx, errors.New(fmt.Errorf("failed to bind json: %w", bindErr), errors.ErrInternalError))
|
|
|
|
}
|
|
|
|
|
|
|
|
account, err := api.account.SetStatus(ctx.Request().Context(), userID, request.Status)
|
|
|
|
if err != nil {
|
|
|
|
api.logger.Error("failed to set status on <SetVerificationStatus> of <AccountService>", zap.Error(err))
|
|
|
|
return errors.HTTP(ctx, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.JSON(http.StatusOK, account)
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
func (api *API2) GetAccount(ctx echo.Context) error {
|
|
|
|
// return receiver.accountController.GetAccount(ctx)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
func (api *API2) AddAccount(ctx echo.Context) error {
|
|
|
|
// return receiver.accountController.CreateAccount(ctx)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
func (api *API2) DeleteDirectAccount(ctx echo.Context, userID string) error {
|
|
|
|
// return receiver.accountController.RemoveDirectAccount(ctx, userID)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API2) GetDirectAccount(ctx echo.Context, userID string) error {
|
|
|
|
// return receiver.accountController.GetDirectAccount(ctx, userID)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API2) PaginationAccounts(ctx echo.Context, params PaginationAccountsParams) error {
|
2023-11-06 08:30:41 +00:00
|
|
|
// return receiver.accountController.GetAccounts(ctx, params)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
// Cart
|
|
|
|
|
2023-11-05 13:58:41 +00:00
|
|
|
func (api *API2) RemoveFromCart(ctx echo.Context, params RemoveFromCartParams) error {
|
2023-11-06 08:30:41 +00:00
|
|
|
// return receiver.cartController.Remove(ctx, params)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API2) Add2cart(ctx echo.Context, params Add2cartParams) error {
|
2023-11-06 08:30:41 +00:00
|
|
|
// return receiver.cartController.Add(ctx, params)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API2) PayCart(ctx echo.Context) error {
|
2023-11-06 08:30:41 +00:00
|
|
|
// return receiver.cartController.Pay(ctx)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
// Currency
|
|
|
|
|
2023-11-05 13:58:41 +00:00
|
|
|
func (api *API2) GetCurrencies(ctx echo.Context) error {
|
2023-11-06 08:30:41 +00:00
|
|
|
// return receiver.currencyController.GetCurrencies(ctx)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API2) UpdateCurrencies(ctx echo.Context) error {
|
2023-11-06 08:30:41 +00:00
|
|
|
// return receiver.currencyController.PutCurrencies(ctx)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
// History
|
|
|
|
|
2023-11-05 13:58:41 +00:00
|
|
|
func (api *API2) GetHistory(ctx echo.Context, params GetHistoryParams) error {
|
2023-11-06 08:30:41 +00:00
|
|
|
// return receiver.historyController.GetHistoryList(ctx, params)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 08:30:41 +00:00
|
|
|
// Wallet
|
2023-11-05 13:58:41 +00:00
|
|
|
|
|
|
|
func (api *API2) RequestMoney(ctx echo.Context) error {
|
2023-11-06 08:30:41 +00:00
|
|
|
// return receiver.walletController.GetPaymentLink(ctx)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API2) ChangeCurrency(ctx echo.Context) error {
|
|
|
|
// return receiver.walletController.ChangeCurrency(ctx)
|
|
|
|
return ctx.JSON(http.StatusBadRequest, models.ResponseErrorHTTP{Message: "TODO", StatusCode: 888})
|
2023-11-05 13:58:41 +00:00
|
|
|
}
|