generated from PenaSide/GolangTemplate
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
![]() |
package history
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/labstack/echo/v4"
|
||
|
"go.uber.org/zap"
|
||
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/swagger"
|
||
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||
|
)
|
||
|
|
||
|
type historyService interface {
|
||
|
GetHistoryList(context.Context, *models.Pagination) (*models.PaginationResponse[models.History], errors.Error)
|
||
|
}
|
||
|
|
||
|
type Deps struct {
|
||
|
Logger *zap.Logger
|
||
|
HistoryService historyService
|
||
|
}
|
||
|
|
||
|
type Controller struct {
|
||
|
logger *zap.Logger
|
||
|
historyService historyService
|
||
|
}
|
||
|
|
||
|
func New(deps Deps) *Controller {
|
||
|
if deps.Logger == nil {
|
||
|
log.Panicln("logger is nil on <New (history controller)>")
|
||
|
}
|
||
|
|
||
|
if deps.HistoryService == nil {
|
||
|
log.Panicln("HistoryService is nil on <New (history controller)>")
|
||
|
}
|
||
|
|
||
|
return &Controller{
|
||
|
logger: deps.Logger,
|
||
|
historyService: deps.HistoryService,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (receiver *Controller) GetHistoryList(ctx echo.Context, params swagger.GetHistoryParams) error {
|
||
|
histories, err := receiver.historyService.GetHistoryList(ctx.Request().Context(), &models.Pagination{
|
||
|
Page: int64(*params.Page),
|
||
|
Limit: int64(*params.Limit),
|
||
|
})
|
||
|
if err != nil {
|
||
|
receiver.logger.Error("failed to get histories on <GetHistoryList> of <HistoryController>", zap.Error(err))
|
||
|
return errors.HTTP(ctx, err)
|
||
|
}
|
||
|
|
||
|
return ctx.JSON(http.StatusOK, histories)
|
||
|
}
|