2024-07-12 09:37:56 +00:00
|
|
|
package currency_client
|
2024-05-21 13:50:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http"
|
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/repository"
|
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Deps struct {
|
|
|
|
CurrencyRepo *repository.CurrencyRepository
|
|
|
|
MiddleWare *http.MiddleWare
|
|
|
|
Logger *zap.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
type CurrencyController struct {
|
|
|
|
currencyRepo *repository.CurrencyRepository
|
|
|
|
middleWare *http.MiddleWare
|
|
|
|
logger *zap.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCurrencyController(deps Deps) *CurrencyController {
|
|
|
|
return &CurrencyController{
|
|
|
|
currencyRepo: deps.CurrencyRepo,
|
|
|
|
middleWare: deps.MiddleWare,
|
|
|
|
logger: deps.Logger,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-23 07:15:26 +00:00
|
|
|
func (receiver *CurrencyController) Get(ctx *fiber.Ctx) error {
|
2024-05-21 13:50:26 +00:00
|
|
|
currencyList, err := receiver.currencyRepo.FindCurrenciesList(ctx.Context(), models.DefaultCurrencyListName)
|
|
|
|
if err != nil && err.Type() != errors.ErrNotFound {
|
|
|
|
return receiver.middleWare.ErrorOld(ctx, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && err.Type() == errors.ErrNotFound {
|
|
|
|
return ctx.Status(fiber.StatusOK).JSON([]string{})
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.Status(fiber.StatusOK).JSON(currencyList)
|
|
|
|
}
|