2024-10-25 10:17:27 +00:00
|
|
|
package svc
|
|
|
|
|
2024-10-25 16:42:58 +00:00
|
|
|
import (
|
|
|
|
"app-cloudep-trade-service/internal/config"
|
2024-10-27 16:01:55 +00:00
|
|
|
duc "app-cloudep-trade-service/internal/domain/usecase"
|
2024-10-29 08:17:31 +00:00
|
|
|
"app-cloudep-trade-service/internal/model"
|
2024-10-27 16:01:55 +00:00
|
|
|
"app-cloudep-trade-service/internal/usecase"
|
2024-10-25 16:42:58 +00:00
|
|
|
|
|
|
|
ers "code.30cm.net/digimon/library-go/errs"
|
|
|
|
"code.30cm.net/digimon/library-go/errs/code"
|
|
|
|
vi "code.30cm.net/digimon/library-go/validator"
|
|
|
|
)
|
2024-10-25 10:17:27 +00:00
|
|
|
|
|
|
|
type ServiceContext struct {
|
2024-10-27 16:01:55 +00:00
|
|
|
Config config.Config
|
|
|
|
Validate vi.Validate
|
|
|
|
|
|
|
|
OrderUseCase duc.OrderUseCase
|
2024-10-29 08:17:31 +00:00
|
|
|
WalletModel model.WalletModel
|
2024-10-25 10:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
2024-10-25 16:42:58 +00:00
|
|
|
// TODO 改成 Trade
|
|
|
|
ers.Scope = code.CloudEPOrder
|
|
|
|
|
2024-10-27 16:01:55 +00:00
|
|
|
om := MustOrderModel(c)
|
|
|
|
orderUseCase := usecase.NewOrderUseCase(usecase.OrderUseCaseParam{
|
|
|
|
OrderModel: om,
|
|
|
|
})
|
|
|
|
|
2024-10-29 08:17:31 +00:00
|
|
|
mysql, err := newDatabase(c)
|
|
|
|
if err != nil {
|
|
|
|
panic("failed to connect to wallet")
|
|
|
|
}
|
|
|
|
|
2024-10-25 10:17:27 +00:00
|
|
|
return &ServiceContext{
|
|
|
|
Config: c,
|
2024-10-25 16:42:58 +00:00
|
|
|
Validate: vi.MustValidator(
|
|
|
|
WithDecimalGt(),
|
|
|
|
WithDecimalGte(),
|
|
|
|
),
|
2024-10-27 16:01:55 +00:00
|
|
|
|
|
|
|
OrderUseCase: orderUseCase,
|
2024-10-29 08:17:31 +00:00
|
|
|
WalletModel: MustWalletModel(mysql),
|
2024-10-25 10:17:27 +00:00
|
|
|
}
|
|
|
|
}
|