internal/repository/factory.go
Rama main · réplica de lectura del repositorio original.
package repository
import (
"github.com/flexprice/flexprice/internal/cache"
"github.com/flexprice/flexprice/internal/clickhouse"
"github.com/flexprice/flexprice/internal/config"
domainActivity "github.com/flexprice/flexprice/internal/domain/activity"
"github.com/flexprice/flexprice/internal/domain/addon"
"github.com/flexprice/flexprice/internal/domain/addonassociation"
"github.com/flexprice/flexprice/internal/domain/addonpricesync"
"github.com/flexprice/flexprice/internal/domain/alert"
"github.com/flexprice/flexprice/internal/domain/alertlogs"
domainAnalytics "github.com/flexprice/flexprice/internal/domain/analytics"
"github.com/flexprice/flexprice/internal/domain/auth"
"github.com/flexprice/flexprice/internal/domain/billingentity"
"github.com/flexprice/flexprice/internal/domain/billingterm"
"github.com/flexprice/flexprice/internal/domain/checkout"
"github.com/flexprice/flexprice/internal/domain/commitment"
"github.com/flexprice/flexprice/internal/domain/connection"
"github.com/flexprice/flexprice/internal/domain/costsheet"
"github.com/flexprice/flexprice/internal/domain/coupon"
"github.com/flexprice/flexprice/internal/domain/coupon_application"
"github.com/flexprice/flexprice/internal/domain/coupon_association"
"github.com/flexprice/flexprice/internal/domain/creditgrant"
"github.com/flexprice/flexprice/internal/domain/creditgrantapplication"
"github.com/flexprice/flexprice/internal/domain/creditnote"
"github.com/flexprice/flexprice/internal/domain/customer"
"github.com/flexprice/flexprice/internal/domain/entitlement"
"github.com/flexprice/flexprice/internal/domain/entitlementgrant"
"github.com/flexprice/flexprice/internal/domain/entityintegrationmapping"
"github.com/flexprice/flexprice/internal/domain/environment"
"github.com/flexprice/flexprice/internal/domain/events"
"github.com/flexprice/flexprice/internal/domain/feature"
fxrate "github.com/flexprice/flexprice/internal/domain/fxrate"
"github.com/flexprice/flexprice/internal/domain/group"
"github.com/flexprice/flexprice/internal/domain/hostedinvoicetoken"
"github.com/flexprice/flexprice/internal/domain/incomingwebhookevent"
"github.com/flexprice/flexprice/internal/domain/invoice"
"github.com/flexprice/flexprice/internal/domain/meter"
"github.com/flexprice/flexprice/internal/domain/meterusagecheckpoint"
"github.com/flexprice/flexprice/internal/domain/payment"
"github.com/flexprice/flexprice/internal/domain/paymentmethod"
"github.com/flexprice/flexprice/internal/domain/plan"
"github.com/flexprice/flexprice/internal/domain/planpricesync"
"github.com/flexprice/flexprice/internal/domain/price"
"github.com/flexprice/flexprice/internal/domain/priceunit"
"github.com/flexprice/flexprice/internal/domain/refund"
"github.com/flexprice/flexprice/internal/domain/revenuefact"
"github.com/flexprice/flexprice/internal/domain/scheduledtask"
"github.com/flexprice/flexprice/internal/domain/secret"
domainsb "github.com/flexprice/flexprice/internal/domain/selfbilling"
"github.com/flexprice/flexprice/internal/domain/settings"
"github.com/flexprice/flexprice/internal/domain/subscription"
domainsystemevent "github.com/flexprice/flexprice/internal/domain/systemevent"
"github.com/flexprice/flexprice/internal/domain/task"
taxrate "github.com/flexprice/flexprice/internal/domain/tax"
taxapplied "github.com/flexprice/flexprice/internal/domain/taxapplied"
"github.com/flexprice/flexprice/internal/domain/taxassociation"
"github.com/flexprice/flexprice/internal/domain/tenant"
"github.com/flexprice/flexprice/internal/domain/usagerecord"
"github.com/flexprice/flexprice/internal/domain/user"
"github.com/flexprice/flexprice/internal/domain/wallet"
"github.com/flexprice/flexprice/internal/domain/workflowexecution"
"github.com/flexprice/flexprice/internal/logger"
"github.com/flexprice/flexprice/internal/postgres"
accountingPeriodRepo "github.com/flexprice/flexprice/internal/repository/accountingperiod"
clickhouseRepo "github.com/flexprice/flexprice/internal/repository/clickhouse"
contractRepo "github.com/flexprice/flexprice/internal/repository/contract"
entRepo "github.com/flexprice/flexprice/internal/repository/ent"
journalRepo "github.com/flexprice/flexprice/internal/repository/journal"
pobRepo "github.com/flexprice/flexprice/internal/repository/pob"
productRepo "github.com/flexprice/flexprice/internal/repository/product"
"github.com/flexprice/flexprice/internal/tracing"
"go.uber.org/fx"
)
// InitTracing wires the tracing service into the ent, clickhouse and cache
// packages so their (call-site-only) StartRepositorySpan / StartCacheSpan
// helpers emit real spans. Repository constructors don't take *tracing.Service
// directly — this avoids threading it through every one of them — so this
// must run once during startup, before any repository or cache call runs.
func InitTracing(tracingSvc *tracing.Service) {
entRepo.SetTracingService(tracingSvc)
clickhouseRepo.SetTracingService(tracingSvc)
cache.SetTracingService(tracingSvc)
}
// RepositoryParams holds common dependencies for repositories
type RepositoryParams struct {
fx.In
Logger *logger.Logger
EntClient postgres.IClient
ClickHouseDB *clickhouse.ClickHouseStore
InMemoryCache cache.InMemoryCache
RedisCache cache.RedisCache
}
func NewEventRepository(p RepositoryParams) events.Repository {
return clickhouseRepo.NewEventRepository(p.ClickHouseDB, p.Logger)
}
func NewProcessedEventRepository(p RepositoryParams) events.ProcessedEventRepository {
return clickhouseRepo.NewProcessedEventRepository(p.ClickHouseDB, p.Logger)
}
func NewRawEventRepository(p RepositoryParams) events.RawEventRepository {
return clickhouseRepo.NewRawEventRepository(p.ClickHouseDB, p.Logger)
}
func NewMeterRepository(p RepositoryParams) meter.Repository {
return entRepo.NewMeterRepository(p.EntClient, p.Logger, p.InMemoryCache)
}
func NewUserRepository(p RepositoryParams) user.Repository {
return entRepo.NewUserRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewAuthRepository(p RepositoryParams) auth.Repository {
return entRepo.NewAuthRepository(p.EntClient, p.Logger)
}
func NewPriceRepository(p RepositoryParams) price.Repository {
return entRepo.NewPriceRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewCustomerRepository(p RepositoryParams) customer.Repository {
return entRepo.NewCustomerRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewPlanRepository(p RepositoryParams) plan.Repository {
return entRepo.NewPlanRepository(p.EntClient, p.Logger, p.InMemoryCache)
}
func NewPlanPriceSyncRepository(p RepositoryParams) planpricesync.Repository {
return entRepo.NewPlanPriceSyncRepository(p.EntClient, p.Logger)
}
func NewAddonPriceSyncRepository(p RepositoryParams) addonpricesync.Repository {
return entRepo.NewAddonPriceSyncRepository(p.EntClient, p.Logger)
}
func NewSubscriptionRepository(p RepositoryParams) subscription.Repository {
return entRepo.NewSubscriptionRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewSubscriptionLineItemRepository(p RepositoryParams) subscription.LineItemRepository {
return entRepo.NewSubscriptionLineItemRepository(p.EntClient, p.Logger)
}
func NewSubscriptionPhaseRepository(p RepositoryParams) subscription.SubscriptionPhaseRepository {
return entRepo.NewSubscriptionPhaseRepository(p.EntClient, p.Logger)
}
func NewSubscriptionScheduleRepository(p RepositoryParams) subscription.SubscriptionScheduleRepository {
return entRepo.NewSubscriptionScheduleRepository(p.EntClient, p.Logger)
}
func NewWalletRepository(p RepositoryParams) wallet.Repository {
return entRepo.NewWalletRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewTenantRepository(p RepositoryParams) tenant.Repository {
return entRepo.NewTenantRepository(p.EntClient, p.Logger, p.InMemoryCache, p.RedisCache)
}
func NewEnvironmentRepository(p RepositoryParams) environment.Repository {
return entRepo.NewEnvironmentRepository(p.EntClient, p.Logger, p.InMemoryCache)
}
func NewInvoiceRepository(p RepositoryParams) invoice.Repository {
return entRepo.NewInvoiceRepository(p.EntClient, p.Logger)
}
func NewInvoiceLineItemRepository(p RepositoryParams) invoice.LineItemRepository {
return entRepo.NewInvoiceLineItemRepository(p.EntClient, p.Logger)
}
func NewFeatureRepository(p RepositoryParams) feature.Repository {
return entRepo.NewFeatureRepository(p.EntClient, p.Logger, p.InMemoryCache, p.RedisCache)
}
func NewEntitlementRepository(p RepositoryParams) entitlement.Repository {
return entRepo.NewEntitlementRepository(p.EntClient, p.Logger, p.InMemoryCache, p.RedisCache)
}
func NewMeterUsageCheckpointRepository(p RepositoryParams) meterusagecheckpoint.Repository {
return entRepo.NewMeterUsageCheckpointRepository(p.EntClient, p.Logger)
}
func NewCommitmentRepository(p RepositoryParams) commitment.Repository {
return entRepo.NewCommitmentRepository(p.EntClient, p.Logger)
}
// NewBillingTermRepository provides the billing term repository.
func NewBillingTermRepository(p RepositoryParams) billingterm.TermRepository {
return entRepo.NewBillingTermRepository(p.EntClient, p.Logger)
}
// NewBillingInstalmentRepository provides the billing instalment repository.
func NewBillingInstalmentRepository(p RepositoryParams) billingterm.InstalmentRepository {
return entRepo.NewBillingInstalmentRepository(p.EntClient, p.Logger)
}
func NewBillingEntityRepository(p RepositoryParams) billingentity.Repository {
return entRepo.NewBillingEntityRepository(p.EntClient, p.Logger)
}
func NewEntitlementGrantRepository(p RepositoryParams) entitlementgrant.Repository {
return entRepo.NewEntitlementGrantRepository(p.EntClient, p.Logger)
}
func NewPaymentRepository(p RepositoryParams) payment.Repository {
return entRepo.NewPaymentRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewPaymentMethodRepository(p RepositoryParams) paymentmethod.Repository {
return entRepo.NewPaymentMethodRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewRefundRepository(p RepositoryParams) refund.Repository {
return entRepo.NewRefundRepository(p.EntClient, p.Logger)
}
func NewTaskRepository(p RepositoryParams) task.Repository {
return entRepo.NewTaskRepository(p.EntClient, p.Logger)
}
func NewSecretRepository(p RepositoryParams) secret.Repository {
return entRepo.NewSecretRepository(p.EntClient, p.Logger, p.InMemoryCache)
}
func NewCreditGrantRepository(p RepositoryParams) creditgrant.Repository {
return entRepo.NewCreditGrantRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewCostsheetRepository(p RepositoryParams) costsheet.Repository {
return entRepo.NewCostsheetRepository(p.EntClient, p.Logger)
}
func NewCreditGrantApplicationRepository(p RepositoryParams) creditgrantapplication.Repository {
return entRepo.NewCreditGrantApplicationRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewCouponRepository(p RepositoryParams) coupon.Repository {
return entRepo.NewCouponRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewCouponAssociationRepository(p RepositoryParams) coupon_association.Repository {
return entRepo.NewCouponAssociationRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewCouponApplicationRepository(p RepositoryParams) coupon_application.Repository {
return entRepo.NewCouponApplicationRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewCreditNoteRepository(p RepositoryParams) creditnote.Repository {
return entRepo.NewCreditNoteRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewCreditNoteLineItemRepository(p RepositoryParams) creditnote.CreditNoteLineItemRepository {
return entRepo.NewCreditNoteLineItemRepository(p.EntClient, p.Logger)
}
func NewConnectionRepository(p RepositoryParams) connection.Repository {
return entRepo.NewConnectionRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewEntityIntegrationMappingRepository(p RepositoryParams) entityintegrationmapping.Repository {
return entRepo.NewEntityIntegrationMappingRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewUsageRecordRepository(p RepositoryParams) usagerecord.Repository {
return entRepo.NewUsageRecordRepository(p.EntClient, p.Logger)
}
func NewTaxRateRepository(p RepositoryParams) taxrate.Repository {
return entRepo.NewTaxRateRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewFXRateRepository(p RepositoryParams) fxrate.Repository {
return entRepo.NewFXRateRepository(p.EntClient, p.Logger)
}
func NewHostedInvoiceTokenRepository(p RepositoryParams) hostedinvoicetoken.Repository {
return entRepo.NewHostedInvoiceTokenRepository(p.EntClient, p.Logger)
}
func NewTaxAssociationRepository(p RepositoryParams) taxassociation.Repository {
return entRepo.NewTaxAssociationRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewTaxAppliedRepository(p RepositoryParams) taxapplied.Repository {
return entRepo.NewTaxAppliedRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewPriceUnitRepository(p RepositoryParams) priceunit.Repository {
return entRepo.NewPriceUnitRepository(p.EntClient, p.Logger, p.InMemoryCache)
}
func NewProductRepository(p RepositoryParams) productRepo.Repository {
return productRepo.NewRepository(p.EntClient, p.Logger)
}
func NewContractRepository(p RepositoryParams) contractRepo.Repository {
return contractRepo.NewRepository(p.EntClient, p.Logger)
}
func NewPerformanceObligationRepository(p RepositoryParams) pobRepo.Repository {
return pobRepo.NewRepository(p.EntClient, p.Logger)
}
func NewAccountingPeriodRepository(p RepositoryParams) accountingPeriodRepo.Repository {
return accountingPeriodRepo.NewRepository(p.EntClient, p.Logger)
}
func NewJournalRepository(p RepositoryParams) journalRepo.Repository {
return journalRepo.NewRepository(p.EntClient, p.Logger)
}
func NewAddonRepository(p RepositoryParams) addon.Repository {
return entRepo.NewAddonRepository(p.EntClient, p.Logger, p.InMemoryCache)
}
func NewAddonAssociationRepository(p RepositoryParams) addonassociation.Repository {
return entRepo.NewAddonAssociationRepository(p.EntClient, p.Logger, p.RedisCache)
}
func NewSettingsRepository(p RepositoryParams) settings.Repository {
return entRepo.NewSettingsRepository(p.EntClient, p.Logger, p.InMemoryCache)
}
func NewAlertLogsRepository(p RepositoryParams) alertlogs.Repository {
return entRepo.NewAlertLogsRepository(p.EntClient, p.Logger)
}
func NewAlertSettingsRepository(p RepositoryParams) alert.Repository {
return entRepo.NewAlertSettingsRepository(p.EntClient, p.Logger)
}
func NewSystemEventRepository(p RepositoryParams) *entRepo.SystemEventRepository {
return entRepo.NewSystemEventRepository(p.EntClient)
}
func NewSystemEventDomainRepository(repo *entRepo.SystemEventRepository) domainsystemevent.Repository {
return repo
}
func NewGroupRepository(p RepositoryParams) group.Repository {
return entRepo.NewGroupRepository(p.EntClient, p.Logger, p.InMemoryCache)
}
func NewScheduledTaskRepository(p RepositoryParams) scheduledtask.Repository {
return entRepo.NewScheduledTaskRepository(p.EntClient, p.Logger)
}
func NewMeterUsageRepository(p RepositoryParams) events.MeterUsageRepository {
return clickhouseRepo.NewMeterUsageRepository(p.ClickHouseDB, p.Logger)
}
func NewActivityRepository(p RepositoryParams) domainActivity.Repository {
return clickhouseRepo.NewActivityRepository(p.ClickHouseDB, p.Logger)
}
func NewWorkflowExecutionRepository(p RepositoryParams) workflowexecution.Repository {
return entRepo.NewWorkflowExecutionRepository(p.EntClient, p.Logger)
}
func NewIncomingWebhookEventRepository(p RepositoryParams) incomingwebhookevent.Repository {
return entRepo.NewIncomingWebhookEventRepository(p.EntClient)
}
func NewCheckoutSessionRepository(p RepositoryParams) checkout.Repository {
return entRepo.NewCheckoutSessionRepository(p.EntClient, p.Logger)
}
func NewAnalyticsViewRepository(p RepositoryParams) domainAnalytics.Repository {
return entRepo.NewAnalyticsViewRepository(p.EntClient, p.Logger)
}
func NewReportsRepository(cfg *config.Configuration, log *logger.Logger, rc cache.RedisCache) (domainAnalytics.ReportsRepository, error) {
return clickhouseRepo.NewReportsRepository(cfg, log, rc)
}
func NewRevenueFactRepository(p RepositoryParams) revenuefact.Repository {
return entRepo.NewRevenueFactRepository(p.EntClient, p.Logger)
}
func NewSelfBillingClickHouseRepository(p RepositoryParams) domainsb.ClickHouseRepository {
return clickhouseRepo.NewSelfBillingRepository(p.ClickHouseDB, p.Logger)
}
func NewSelfBillingPostgresRepository(p RepositoryParams) domainsb.PostgresRepository {
return entRepo.NewSelfBillingRepository(p.EntClient, p.Logger)
}
func NewEventDeletionRequestRepository(p RepositoryParams) events.DeletionRequestRepository {
return entRepo.NewEventDeletionRequestRepository(p.EntClient, p.Logger)
}
func NewEventDeletionLogRepository(p RepositoryParams) events.DeletedEventsLogRepository {
return clickhouseRepo.NewEventDeletionLogRepository(p.ClickHouseDB, p.Logger)
}