generated from PenaSide/GolangTemplate
Merge branch 'dev' into 'staging'
Dev See merge request pena-services/customer!27
This commit is contained in:
commit
b56e3293ea
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
vendor/
|
||||
.idea/
|
||||
.vscode
|
||||
.env
|
||||
|
@ -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
|
||||
}
|
@ -9,20 +9,17 @@ import (
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/customer"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/history"
|
||||
)
|
||||
|
||||
type historyService interface {
|
||||
CreateHistory(ctx context.Context, history *models.History) (*models.History, errors.Error)
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Logger *zap.Logger
|
||||
HistoryService historyService
|
||||
HistoryService *history.Service
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
logger *zap.Logger
|
||||
historyService historyService
|
||||
historyService *history.Service
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
|
@ -9,21 +9,17 @@ import (
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/payment_callback"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/callback"
|
||||
)
|
||||
|
||||
type paymentCallbackService interface {
|
||||
SuccessEvent(context.Context, *models.PaymentEvent) errors.Error
|
||||
FailureEvent(context.Context, *models.PaymentEvent) errors.Error
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Logger *zap.Logger
|
||||
PaymentCallbackService paymentCallbackService
|
||||
PaymentCallbackService *callback.PaymentCallbackService
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
logger *zap.Logger
|
||||
paymentCallbackService paymentCallbackService
|
||||
paymentCallbackService *callback.PaymentCallbackService
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -11,29 +10,19 @@ import (
|
||||
"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/account"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/utils"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/echotools"
|
||||
)
|
||||
|
||||
type accountService interface {
|
||||
GetAccountByUserID(ctx context.Context, userID string) (*models.Account, errors.Error)
|
||||
GetAccountsList(ctx context.Context, pagination *models.Pagination) (*models.PaginationResponse[models.Account], errors.Error)
|
||||
CreateAccount(ctx context.Context, account *models.Account) (*models.Account, errors.Error)
|
||||
CreateAccountByUserID(ctx context.Context, userID string) (*models.Account, errors.Error)
|
||||
RemoveAccount(ctx context.Context, userID string) (*models.Account, errors.Error)
|
||||
DeleteAccount(ctx context.Context, userID string) (*models.Account, errors.Error)
|
||||
SetVerificationStatus(ctx context.Context, userID string, status models.AccountStatus) (*models.Account, errors.Error)
|
||||
UpdateAccountName(ctx context.Context, userID string, name *models.Name) (*models.Account, errors.Error)
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Logger *zap.Logger
|
||||
Service accountService
|
||||
Service *account.Service
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
logger *zap.Logger
|
||||
service accountService
|
||||
service *account.Service
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cart
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -11,23 +10,18 @@ import (
|
||||
"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/cart"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/validate"
|
||||
)
|
||||
|
||||
type cartService interface {
|
||||
Remove(ctx context.Context, userID, itemID string) (*models.Account, errors.Error)
|
||||
Add(context.Context, *models.AddItemToCart) (*models.Account, errors.Error)
|
||||
Pay(ctx context.Context, token, userID string) (*models.Account, errors.Error)
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Logger *zap.Logger
|
||||
CartService cartService
|
||||
CartService *cart.Service
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
logger *zap.Logger
|
||||
cartService cartService
|
||||
cartService *cart.Service
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package currency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -9,22 +8,18 @@ import (
|
||||
"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/service/currency"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/echotools"
|
||||
)
|
||||
|
||||
type currencyService interface {
|
||||
GetCurrencies(context.Context) ([]string, errors.Error)
|
||||
PutCurrencies(context.Context, []string) ([]string, errors.Error)
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Logger *zap.Logger
|
||||
CurrencyService currencyService
|
||||
CurrencyService *currency.Service
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
logger *zap.Logger
|
||||
currencyService currencyService
|
||||
currencyService *currency.Service
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
|
@ -1,32 +1,26 @@
|
||||
package history
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"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)
|
||||
GetRecentTariffs(context.Context, string) ([]models.TariffID, errors.Error) // new
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Logger *zap.Logger
|
||||
HistoryService historyService
|
||||
HistoryService *history.Service
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
logger *zap.Logger
|
||||
historyService historyService
|
||||
historyService *history.Service
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
@ -55,7 +49,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{
|
||||
|
@ -1,7 +1,6 @@
|
||||
package wallet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -10,30 +9,23 @@ import (
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/payment"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/wallet"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/utils"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/echotools"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/validate"
|
||||
)
|
||||
|
||||
type walletService interface {
|
||||
ReplenishAccountWallet(context.Context, *models.ReplenishAccountWallet) (*models.Account, errors.Error)
|
||||
ChangeCurrency(ctx context.Context, userID string, currency models.CurrencyKey) (*models.Account, errors.Error)
|
||||
}
|
||||
|
||||
type paymentService interface {
|
||||
GetPaymentLink(context.Context, *models.GetPaymentLinkRequest) (string, errors.Error)
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Logger *zap.Logger
|
||||
WalletService walletService
|
||||
PaymentService paymentService
|
||||
WalletService *wallet.Service
|
||||
PaymentService *payment.Service
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
logger *zap.Logger
|
||||
walletService walletService
|
||||
paymentService paymentService
|
||||
walletService *wallet.Service
|
||||
paymentService *payment.Service
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
|
@ -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>",
|
||||
@ -120,6 +120,18 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID
|
||||
}},
|
||||
}
|
||||
|
||||
unwindStage := bson.D{
|
||||
{Key: "$unwind", Value: bson.D{
|
||||
{Key: "path", Value: "$rawDetails.tariffs"},
|
||||
}},
|
||||
}
|
||||
|
||||
groupStage := bson.D{
|
||||
{Key: "$group", Value: bson.D{
|
||||
{Key: "_id", Value: "$rawDetails.tariffs.id"},
|
||||
}},
|
||||
}
|
||||
|
||||
sortStage := bson.D{
|
||||
{Key: "$sort", Value: bson.D{
|
||||
{Key: "createdAt", Value: -1},
|
||||
@ -130,7 +142,7 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID
|
||||
{Key: "$limit", Value: 100},
|
||||
}
|
||||
|
||||
cursor, err := receiver.mongoDB.Aggregate(ctx, mongo.Pipeline{matchStage, sortStage, limitStage})
|
||||
cursor, err := receiver.mongoDB.Aggregate(ctx, mongo.Pipeline{matchStage, unwindStage, sortStage, groupStage, limitStage})
|
||||
if err != nil {
|
||||
receiver.logger.Error("failed to get recent tariffs on <GetRecentTariffs> of <HistoryRepository>",
|
||||
zap.String("userId", userID),
|
||||
|
@ -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