generated from PenaSide/GolangTemplate
move GetHistories
This commit is contained in:
parent
fa91bac30f
commit
5114839587
@ -1,23 +0,0 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/fields"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
)
|
||||
|
||||
type GetHistories struct {
|
||||
Pagination *models.Pagination
|
||||
Type *string
|
||||
UserID string
|
||||
}
|
||||
|
||||
func (receiver *GetHistories) BSON() bson.M {
|
||||
query := bson.M{
|
||||
fields.History.IsDeleted: false,
|
||||
fields.History.Type: *receiver.Type,
|
||||
fields.History.UserID: receiver.UserID,
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
@ -8,14 +8,14 @@ import (
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/dto"
|
||||
"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"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/history"
|
||||
)
|
||||
|
||||
type historyService interface {
|
||||
GetHistoryList(context.Context, *dto.GetHistories) (*models.PaginationResponse[models.History], errors.Error)
|
||||
GetHistoryList(context.Context, *history.GetHistories) (*models.PaginationResponse[models.History], errors.Error)
|
||||
GetRecentTariffs(context.Context, string) ([]models.TariffID, errors.Error) // new
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ func (receiver *Controller) GetHistoryList(ctx echo.Context, params swagger.GetH
|
||||
))
|
||||
}
|
||||
|
||||
histories, err := receiver.historyService.GetHistoryList(ctx.Request().Context(), &dto.GetHistories{
|
||||
histories, err := receiver.historyService.GetHistoryList(ctx.Request().Context(), &history.GetHistories{
|
||||
Type: params.Type,
|
||||
UserID: userID,
|
||||
Pagination: &models.Pagination{
|
||||
|
@ -10,10 +10,10 @@ import (
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/dto"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/fields"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/history"
|
||||
mongoWrapper "penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/mongo"
|
||||
)
|
||||
|
||||
@ -62,7 +62,7 @@ func (receiver *HistoryRepository) Insert(ctx context.Context, history *models.H
|
||||
return history, nil
|
||||
}
|
||||
|
||||
func (receiver *HistoryRepository) FindMany(ctx context.Context, dto *dto.GetHistories) ([]models.History, errors.Error) {
|
||||
func (receiver *HistoryRepository) FindMany(ctx context.Context, dto *history.GetHistories) ([]models.History, errors.Error) {
|
||||
findOptions := options.Find()
|
||||
|
||||
findOptions.SetSkip((dto.Pagination.Page - 1) * dto.Pagination.Limit)
|
||||
@ -93,7 +93,7 @@ func (receiver *HistoryRepository) FindMany(ctx context.Context, dto *dto.GetHis
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
func (receiver *HistoryRepository) CountAll(ctx context.Context, dto *dto.GetHistories) (int64, errors.Error) {
|
||||
func (receiver *HistoryRepository) CountAll(ctx context.Context, dto *history.GetHistories) (int64, errors.Error) {
|
||||
count, err := receiver.mongoDB.CountDocuments(ctx, dto.BSON())
|
||||
if err != nil {
|
||||
receiver.logger.Error("failed to count all documents on <CountAll> of <HistoryRepository>",
|
||||
|
@ -6,15 +6,31 @@ import (
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/dto"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/fields"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
)
|
||||
|
||||
type GetHistories struct {
|
||||
Pagination *models.Pagination
|
||||
Type *string
|
||||
UserID string
|
||||
}
|
||||
|
||||
func (receiver *GetHistories) BSON() bson.M {
|
||||
query := bson.M{
|
||||
fields.History.IsDeleted: false,
|
||||
fields.History.Type: *receiver.Type,
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
type historyRepository interface {
|
||||
CountAll(context.Context, *dto.GetHistories) (int64, errors.Error)
|
||||
FindMany(context.Context, *dto.GetHistories) ([]models.History, errors.Error)
|
||||
CountAll(context.Context, *GetHistories) (int64, errors.Error)
|
||||
FindMany(context.Context, *GetHistories) ([]models.History, errors.Error)
|
||||
Insert(context.Context, *models.History) (*models.History, errors.Error)
|
||||
GetRecentTariffs(context.Context, string) ([]models.TariffID, errors.Error) // new
|
||||
}
|
||||
@ -44,7 +60,7 @@ func New(deps Deps) *Service {
|
||||
}
|
||||
}
|
||||
|
||||
func (receiver *Service) GetHistoryList(ctx context.Context, dto *dto.GetHistories) (*models.PaginationResponse[models.History], errors.Error) {
|
||||
func (receiver *Service) GetHistoryList(ctx context.Context, dto *GetHistories) (*models.PaginationResponse[models.History], errors.Error) {
|
||||
if dto == nil {
|
||||
return nil, errors.New(
|
||||
fmt.Errorf("pagination is nil on <GetHistoryList> of <HistoryService>: %w", errors.ErrInternalError),
|
||||
|
Loading…
Reference in New Issue
Block a user