解耦订单和申诉模块外部依赖
This commit is contained in:
@@ -109,9 +109,30 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
||||
if deps.DB != nil {
|
||||
listingRepo = listing.NewRepository(deps.DB)
|
||||
}
|
||||
var chatHub *chathub.Hub
|
||||
if deps.DB != nil {
|
||||
chatHub = chathub.NewHub(deps.DB)
|
||||
}
|
||||
var chatRepo *chat.Repository
|
||||
if deps.DB != nil {
|
||||
chatRepo = chat.NewRepository(deps.DB, chatHub)
|
||||
}
|
||||
var paymentRepo *payment.Repository
|
||||
var orderRepo *order.Repository
|
||||
if deps.DB != nil {
|
||||
orderRepo = order.NewRepository(deps.DB)
|
||||
orderRepo = order.NewRepository(deps.DB, order.Dependencies{
|
||||
ChatNotifier: chatRepo,
|
||||
RefundStarter: order.RefundStarterFunc(func(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string, remark string) (string, error) {
|
||||
if paymentRepo == nil {
|
||||
return "", order.ErrDependencyUnavailable
|
||||
}
|
||||
dto, err := paymentRepo.StartRefund(ctx, orderID, refundAmountCent, bizType, remark)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dto.Status, nil
|
||||
}),
|
||||
})
|
||||
}
|
||||
orderService := order.NewService(orderRepo)
|
||||
orderHandler := order.NewHandler(orderService)
|
||||
@@ -156,56 +177,36 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
||||
paymentConfigHandler = paymentconfig.NewHandler(paymentConfigService)
|
||||
}
|
||||
|
||||
var paymentRepo *payment.Repository
|
||||
if deps.DB != nil {
|
||||
paymentRepo = payment.NewRepository(deps.DB, paymentConfigRepo, orderRepo, walletRepo)
|
||||
}
|
||||
paymentService := payment.NewService(paymentRepo, cfg.AppEnv)
|
||||
paymentHandler := payment.NewHandler(paymentService)
|
||||
// Inject refund function into order repo to avoid circular dependency
|
||||
if orderRepo != nil && paymentRepo != nil {
|
||||
orderRepo.SetRefundFunc(func(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string, remark string) (string, error) {
|
||||
dto, err := paymentRepo.StartRefund(ctx, orderID, refundAmountCent, bizType, remark)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dto.Status, nil
|
||||
})
|
||||
}
|
||||
var notificationRepo *notification.Repository
|
||||
if deps.DB != nil {
|
||||
notificationRepo = notification.NewRepository(deps.DB)
|
||||
}
|
||||
notificationService := notification.NewService(notificationRepo)
|
||||
notificationHandler := notification.NewHandler(notificationService)
|
||||
var chatHub *chathub.Hub
|
||||
if deps.DB != nil {
|
||||
chatHub = chathub.NewHub(deps.DB)
|
||||
}
|
||||
var chatRepo *chat.Repository
|
||||
if deps.DB != nil {
|
||||
chatRepo = chat.NewRepository(deps.DB, chatHub)
|
||||
}
|
||||
chatService := chat.NewService(chatRepo)
|
||||
chatHandler := chat.NewHandler(chatService)
|
||||
var chatHubHandler *chathub.Handler
|
||||
if chatHub != nil {
|
||||
chatHubHandler = chathub.NewHandler(chatHub)
|
||||
}
|
||||
if orderRepo != nil && chatRepo != nil {
|
||||
orderRepo.SetChatRepo(chatRepo)
|
||||
}
|
||||
var disputeRepo *dispute.Repository
|
||||
if deps.DB != nil {
|
||||
disputeRepo = dispute.NewRepository(deps.DB)
|
||||
}
|
||||
if disputeRepo != nil && paymentRepo != nil {
|
||||
disputeRepo.SetRefundFunc(func(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string, remark string) (string, error) {
|
||||
dto, err := paymentRepo.StartRefund(ctx, orderID, refundAmountCent, bizType, remark)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dto.Status, nil
|
||||
disputeRepo = dispute.NewRepository(deps.DB, dispute.Dependencies{
|
||||
RefundStarter: dispute.RefundStarterFunc(func(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string, remark string) (string, error) {
|
||||
if paymentRepo == nil {
|
||||
return "", dispute.ErrDependencyUnavailable
|
||||
}
|
||||
dto, err := paymentRepo.StartRefund(ctx, orderID, refundAmountCent, bizType, remark)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dto.Status, nil
|
||||
}),
|
||||
})
|
||||
}
|
||||
disputeService := dispute.NewService(disputeRepo)
|
||||
|
||||
Reference in New Issue
Block a user