#![recursion_limit = "1024"]
#![allow(unused_imports)]
pub mod domain;
pub mod infrastructure;
pub mod application;
pub mod presentation;
pub mod seeders;
pub mod exports;
pub mod request_pool;
pub use domain::entity::*;
pub use infrastructure::persistence::*;
pub use application::service::BankService;
pub use application::service::BankAccountService;
pub use application::service::BankClearanceService;
pub use application::service::BankReconciliationService;
pub use application::service::BankStatementImportService;
pub use application::service::BankTransactionService;
pub use application::service::FxGainLossService;
pub use application::service::ReconcilePresetService;
pub use application::workflows::*;
use std::sync::Arc;
use axum::Router;
use sqlx::PgPool;
pub struct BankingModule {
pub(crate) bank_service: Arc<BankService>,
pub(crate) bank_account_service: Arc<BankAccountService>,
pub(crate) bank_clearance_service: Arc<BankClearanceService>,
pub(crate) bank_reconciliation_service: Arc<BankReconciliationService>,
pub(crate) bank_statement_import_service: Arc<BankStatementImportService>,
pub(crate) bank_transaction_service: Arc<BankTransactionService>,
pub(crate) fx_gain_loss_service: Arc<FxGainLossService>,
pub(crate) reconcile_preset_service: Arc<ReconcilePresetService>,
}
impl BankingModule {
pub fn builder() -> BankingModuleBuilder {
BankingModuleBuilder::new()
}
pub fn all_crud_routes(&self) -> Router {
use presentation::http::{
create_bank_routes,
create_bank_account_routes,
create_bank_clearance_routes,
create_bank_reconciliation_routes,
create_bank_statement_import_routes,
create_bank_transaction_routes,
create_fx_gain_loss_routes,
create_reconcile_preset_routes,
};
Router::new()
.merge(create_bank_routes(self.bank_service.clone()))
.merge(create_bank_account_routes(self.bank_account_service.clone()))
.merge(create_bank_clearance_routes(self.bank_clearance_service.clone()))
.merge(create_bank_reconciliation_routes(self.bank_reconciliation_service.clone()))
.merge(create_bank_statement_import_routes(self.bank_statement_import_service.clone()))
.merge(create_bank_transaction_routes(self.bank_transaction_service.clone()))
.merge(create_fx_gain_loss_routes(self.fx_gain_loss_service.clone()))
.merge(create_reconcile_preset_routes(self.reconcile_preset_service.clone()))
}
#[deprecated(note = "mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface")]
pub fn routes(&self) -> Router {
self.all_crud_routes()
}
pub fn readonly_routes(&self) -> Router {
use presentation::http::{
create_bank_read_routes,
create_bank_account_read_routes,
create_bank_clearance_read_routes,
create_bank_reconciliation_read_routes,
create_bank_statement_import_read_routes,
create_bank_transaction_read_routes,
create_fx_gain_loss_read_routes,
create_reconcile_preset_read_routes,
};
Router::new()
.merge(create_bank_read_routes(self.bank_service.clone()))
.merge(create_bank_account_read_routes(self.bank_account_service.clone()))
.merge(create_bank_clearance_read_routes(self.bank_clearance_service.clone()))
.merge(create_bank_reconciliation_read_routes(self.bank_reconciliation_service.clone()))
.merge(create_bank_statement_import_read_routes(self.bank_statement_import_service.clone()))
.merge(create_bank_transaction_read_routes(self.bank_transaction_service.clone()))
.merge(create_fx_gain_loss_read_routes(self.fx_gain_loss_service.clone()))
.merge(create_reconcile_preset_read_routes(self.reconcile_preset_service.clone()))
}
}
pub struct BankingModuleBuilder {
db_pool: Option<PgPool>,
}
impl BankingModuleBuilder {
pub fn new() -> Self {
Self {
db_pool: None,
}
}
pub fn with_database(mut self, pool: PgPool) -> Self {
self.db_pool = Some(pool);
self
}
pub fn build(self) -> anyhow::Result<BankingModule> {
let db_pool = self.db_pool
.ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;
let bank_repository = Arc::new(BankRepository::new(db_pool.clone()));
let bank_service = Arc::new(BankService::with_repository(bank_repository.clone()));
let bank_account_repository = Arc::new(BankAccountRepository::new(db_pool.clone()));
let bank_account_service = Arc::new(BankAccountService::with_repository(bank_account_repository.clone()));
let bank_clearance_repository = Arc::new(BankClearanceRepository::new(db_pool.clone()));
let bank_clearance_service = Arc::new(BankClearanceService::with_repository(bank_clearance_repository.clone()));
let bank_reconciliation_repository = Arc::new(BankReconciliationRepository::new(db_pool.clone()));
let bank_reconciliation_service = Arc::new(BankReconciliationService::with_repository(bank_reconciliation_repository.clone()));
let bank_statement_import_repository = Arc::new(BankStatementImportRepository::new(db_pool.clone()));
let bank_statement_import_service = Arc::new(BankStatementImportService::with_repository(bank_statement_import_repository.clone()));
let bank_transaction_repository = Arc::new(BankTransactionRepository::new(db_pool.clone()));
let bank_transaction_service = Arc::new(BankTransactionService::with_repository(bank_transaction_repository.clone()));
let fx_gain_loss_repository = Arc::new(FxGainLossRepository::new(db_pool.clone()));
let fx_gain_loss_service = Arc::new(FxGainLossService::with_repository(fx_gain_loss_repository.clone()));
let reconcile_preset_repository = Arc::new(ReconcilePresetRepository::new(db_pool.clone()));
let reconcile_preset_service = Arc::new(ReconcilePresetService::with_repository(reconcile_preset_repository.clone()));
Ok(BankingModule {
bank_service,
bank_account_service,
bank_clearance_service,
bank_reconciliation_service,
bank_statement_import_service,
bank_transaction_service,
fx_gain_loss_service,
reconcile_preset_service,
})
}
}
impl Default for BankingModuleBuilder {
fn default() -> Self {
Self::new()
}
}