generated from PenaSide/GolangTemplate
feat: payment service initialize
This commit is contained in:
parent
de9ba0e80c
commit
de1aced10b
@ -20,6 +20,8 @@ const (
|
||||
)
|
||||
|
||||
func Run(ctx context.Context, config *models.Config, logger *zap.Logger) error {
|
||||
closer := closer.New()
|
||||
|
||||
mongoDB, err := mongo.Connect(ctx, &mongo.ConnectDeps{
|
||||
Configuration: &config.Database,
|
||||
Timeout: 10 * time.Second,
|
||||
@ -28,6 +30,7 @@ func Run(ctx context.Context, config *models.Config, logger *zap.Logger) error {
|
||||
return fmt.Errorf("failed connection to db: %w", err)
|
||||
}
|
||||
|
||||
// TODO: добавить недостающие зависимости
|
||||
clients := initialize.NewClients(&initialize.ClientsDeps{
|
||||
Logger: logger,
|
||||
AuthURL: &config.Service.AuthMicroservice.URL,
|
||||
@ -56,7 +59,6 @@ func Run(ctx context.Context, config *models.Config, logger *zap.Logger) error {
|
||||
}
|
||||
|
||||
api := initialize.NewAPI(controllers)
|
||||
closer := closer.New()
|
||||
|
||||
httpServer := server.New(&server.Deps{
|
||||
Logger: logger,
|
||||
|
@ -23,11 +23,12 @@ func TestNewAPI(t *testing.T) {
|
||||
})
|
||||
|
||||
clients := initialize.NewClients(&initialize.ClientsDeps{
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{User: ""},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{Tariff: ""},
|
||||
CurrencyURL: &models.CurrencyMicroserviceURL{},
|
||||
DiscountHost: "localhost:8080",
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{User: ""},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{Tariff: ""},
|
||||
CurrencyURL: &models.CurrencyMicroserviceURL{},
|
||||
DiscountServiceHost: "localhost:8080",
|
||||
PaymentServiceHost: "localhost:8081",
|
||||
})
|
||||
|
||||
services := initialize.NewServices(&initialize.ServicesDeps{
|
||||
|
@ -7,11 +7,12 @@ import (
|
||||
)
|
||||
|
||||
type ClientsDeps struct {
|
||||
Logger *zap.Logger
|
||||
AuthURL *models.AuthMicroserviceURL
|
||||
HubadminURL *models.HubadminMicroserviceURL
|
||||
CurrencyURL *models.CurrencyMicroserviceURL
|
||||
DiscountHost string
|
||||
Logger *zap.Logger
|
||||
AuthURL *models.AuthMicroserviceURL
|
||||
HubadminURL *models.HubadminMicroserviceURL
|
||||
CurrencyURL *models.CurrencyMicroserviceURL
|
||||
DiscountServiceHost string
|
||||
PaymentServiceHost string
|
||||
}
|
||||
|
||||
type Clients struct {
|
||||
@ -19,6 +20,7 @@ type Clients struct {
|
||||
HubadminClient *client.HubadminClient
|
||||
CurrencyClient *client.CurrencyClient
|
||||
DiscountClient *client.DiscountClient
|
||||
PaymentClient *client.PaymentClient
|
||||
}
|
||||
|
||||
func NewClients(deps *ClientsDeps) *Clients {
|
||||
@ -37,7 +39,11 @@ func NewClients(deps *ClientsDeps) *Clients {
|
||||
}),
|
||||
DiscountClient: client.NewDiscountClient(&client.DiscountClientDeps{
|
||||
Logger: deps.Logger,
|
||||
DiscountServiceHost: deps.DiscountHost,
|
||||
DiscountServiceHost: deps.DiscountServiceHost,
|
||||
}),
|
||||
PaymentClient: client.NewPaymentClient(client.PaymentClientDeps{
|
||||
Logger: deps.Logger,
|
||||
PaymentServiceHost: deps.PaymentServiceHost,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -15,11 +15,12 @@ func TestNewClients(t *testing.T) {
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
clients := initialize.NewClients(&initialize.ClientsDeps{
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{},
|
||||
CurrencyURL: &models.CurrencyMicroserviceURL{},
|
||||
DiscountHost: "localhost:8080",
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{},
|
||||
CurrencyURL: &models.CurrencyMicroserviceURL{},
|
||||
DiscountServiceHost: "localhost:8080",
|
||||
PaymentServiceHost: "localhost:8081",
|
||||
})
|
||||
|
||||
assert.NotNil(t, clients)
|
||||
@ -27,6 +28,7 @@ func TestNewClients(t *testing.T) {
|
||||
assert.NotNil(t, clients.HubadminClient)
|
||||
assert.NotNil(t, clients.CurrencyClient)
|
||||
assert.NotNil(t, clients.DiscountClient)
|
||||
assert.NotNil(t, clients.PaymentClient)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func setDefaultTestingENV(t *testing.T) *models.Config {
|
||||
}
|
||||
|
||||
defaultConfiguration := models.Config{
|
||||
HTTP: models.HTTPConfiguration{
|
||||
HTTP: models.ConfigurationHTTP{
|
||||
Host: "localhost",
|
||||
Port: "8080",
|
||||
},
|
||||
|
@ -2,17 +2,20 @@ package initialize
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"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/service/cart"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/currency"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/history"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/payment"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/wallet"
|
||||
)
|
||||
|
||||
type ServicesDeps struct {
|
||||
Logger *zap.Logger
|
||||
Repositories *Repositories
|
||||
Clients *Clients
|
||||
Logger *zap.Logger
|
||||
Repositories *Repositories
|
||||
Clients *Clients
|
||||
ConfigurationGRPC *models.ConfigurationGRPC
|
||||
}
|
||||
|
||||
type Services struct {
|
||||
@ -21,6 +24,7 @@ type Services struct {
|
||||
CartService *cart.Service
|
||||
HistoryService *history.Service
|
||||
WalletService *wallet.Service
|
||||
PaymentService *payment.Service
|
||||
}
|
||||
|
||||
func NewServices(deps *ServicesDeps) *Services {
|
||||
@ -31,6 +35,7 @@ func NewServices(deps *ServicesDeps) *Services {
|
||||
})
|
||||
|
||||
return &Services{
|
||||
WalletService: walletService,
|
||||
AccountService: account.New(&account.Deps{
|
||||
Logger: deps.Logger,
|
||||
Repository: deps.Repositories.AccountRepository,
|
||||
@ -51,6 +56,11 @@ func NewServices(deps *ServicesDeps) *Services {
|
||||
Logger: deps.Logger,
|
||||
Repository: deps.Repositories.HistoryRepository,
|
||||
}),
|
||||
WalletService: walletService,
|
||||
PaymentService: payment.New(payment.Deps{
|
||||
Logger: deps.Logger,
|
||||
ConfigurationGRPC: deps.ConfigurationGRPC,
|
||||
PaymentClient: deps.Clients.PaymentClient,
|
||||
AuthClient: deps.Clients.AuthClient,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,12 @@ func TestNewServices(t *testing.T) {
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
clients := initialize.NewClients(&initialize.ClientsDeps{
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{},
|
||||
CurrencyURL: &models.CurrencyMicroserviceURL{},
|
||||
DiscountHost: "localhost:8080",
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{},
|
||||
CurrencyURL: &models.CurrencyMicroserviceURL{},
|
||||
DiscountServiceHost: "localhost:8080",
|
||||
PaymentServiceHost: "localhost:8081",
|
||||
})
|
||||
|
||||
repositories := initialize.NewRepositories(&initialize.RepositoriesDeps{
|
||||
@ -31,9 +32,10 @@ func TestNewServices(t *testing.T) {
|
||||
})
|
||||
|
||||
services := initialize.NewServices(&initialize.ServicesDeps{
|
||||
Logger: logger,
|
||||
Clients: clients,
|
||||
Repositories: repositories,
|
||||
Logger: logger,
|
||||
Clients: clients,
|
||||
Repositories: repositories,
|
||||
ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "http://test:8080"},
|
||||
})
|
||||
|
||||
assert.NotNil(t, services)
|
||||
@ -42,6 +44,7 @@ func TestNewServices(t *testing.T) {
|
||||
assert.NotNil(t, services.CurrencyService)
|
||||
assert.NotNil(t, services.HistoryService)
|
||||
assert.NotNil(t, services.WalletService)
|
||||
assert.NotNil(t, services.PaymentService)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func (receiver *HTTP) Listen(address string) error {
|
||||
return receiver.server.ListenAndServe()
|
||||
}
|
||||
|
||||
func (receiver *HTTP) Run(config *models.HTTPConfiguration) {
|
||||
func (receiver *HTTP) Run(config *models.ConfigurationHTTP) {
|
||||
connectionString := fmt.Sprintf("%s:%s", config.Host, config.Port)
|
||||
startServerMessage := fmt.Sprintf("starting http server on %s", connectionString)
|
||||
|
||||
|
@ -66,6 +66,9 @@ func Connect(ctx context.Context, deps *ConnectDeps) (*mongo.Database, error) {
|
||||
log.Printf("failed to connect to db <%s>: %s", mongoURI.String(), err.Error())
|
||||
case <-timeoutExceeded:
|
||||
return nil, fmt.Errorf("db connection <%s> failed after %d timeout", mongoURI, deps.Timeout)
|
||||
default:
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user