1#![recursion_limit = "1024"]
18#![allow(unused_imports)]
19
20pub mod domain;
22pub mod infrastructure;
23pub mod application;
24pub mod presentation;
25pub mod seeders;
26pub mod exports;
27
28#[path = "lib.ext.rs"]
30mod lib_ext;
31pub use lib_ext::*;
32#[allow(dead_code)]
34pub(crate) type ThisModule = AccountingModule;
35#[allow(dead_code)]
36pub(crate) type ThisModuleBuilder = AccountingModuleBuilder;
37
38pub use domain::entity::*;
40
41pub use infrastructure::persistence::*;
43
44pub use application::service::AccountService;
46pub use application::service::AccountingPostService;
47pub use application::service::CostCenterService;
48pub use application::service::EmvQrConfigService;
49pub use application::service::BankCheckSequenceService;
50pub use application::service::PrintedCheckService;
51pub use application::service::TaxTagRepairRunService;
52pub use application::service::FinancialStatementService;
53pub use application::service::FiscalPeriodService;
54pub use application::service::JournalService;
55pub use application::service::JournalLineService;
56pub use application::service::LedgerService;
57pub use application::service::ReconciliationService;
58pub use application::service::ReconciliationItemService;
59pub use application::service::FullReconcileService;
60pub use application::service::PartialReconcileService;
61
62use std::sync::Arc;
63use axum::Router;
64use sqlx::PgPool;
65
66pub struct AccountingModule {
79 pub(crate) account_service: Arc<AccountService>,
80 pub(crate) accounting_post_service: Arc<AccountingPostService>,
81 pub(crate) cost_center_service: Arc<CostCenterService>,
82 pub(crate) emv_qr_config_service: Arc<EmvQrConfigService>,
83 pub(crate) bank_check_sequence_service: Arc<BankCheckSequenceService>,
84 pub(crate) printed_check_service: Arc<PrintedCheckService>,
85 pub(crate) tax_tag_repair_run_service: Arc<TaxTagRepairRunService>,
86 pub(crate) financial_statement_service: Arc<FinancialStatementService>,
87 pub(crate) fiscal_period_service: Arc<FiscalPeriodService>,
88 pub(crate) journal_service: Arc<JournalService>,
89 pub(crate) journal_line_service: Arc<JournalLineService>,
90 pub(crate) ledger_service: Arc<LedgerService>,
91 pub(crate) reconciliation_service: Arc<ReconciliationService>,
92 pub(crate) reconciliation_item_service: Arc<ReconciliationItemService>,
93 pub(crate) full_reconcile_service: Arc<FullReconcileService>,
94 pub(crate) partial_reconcile_service: Arc<PartialReconcileService>,
95 pub(crate) ext: ModuleExt,
97}
98
99impl std::ops::Deref for AccountingModule {
100 type Target = ModuleExt;
101 fn deref(&self) -> &Self::Target {
102 &self.ext
103 }
104}
105
106impl std::ops::DerefMut for AccountingModule {
107 fn deref_mut(&mut self) -> &mut Self::Target {
108 &mut self.ext
109 }
110}
111
112#[allow(dead_code)]
114pub(crate) struct ModuleParts<'a> {
115 pub(crate) db_pool: &'a PgPool,
116 pub(crate) account_service: &'a Arc<AccountService>,
117 pub(crate) account_repository: &'a Arc<AccountRepository>,
118 pub(crate) accounting_post_service: &'a Arc<AccountingPostService>,
119 pub(crate) accounting_post_repository: &'a Arc<AccountingPostRepository>,
120 pub(crate) cost_center_service: &'a Arc<CostCenterService>,
121 pub(crate) cost_center_repository: &'a Arc<CostCenterRepository>,
122 pub(crate) emv_qr_config_service: &'a Arc<EmvQrConfigService>,
123 pub(crate) emv_qr_config_repository: &'a Arc<EmvQrConfigRepository>,
124 pub(crate) bank_check_sequence_service: &'a Arc<BankCheckSequenceService>,
125 pub(crate) bank_check_sequence_repository: &'a Arc<BankCheckSequenceRepository>,
126 pub(crate) printed_check_service: &'a Arc<PrintedCheckService>,
127 pub(crate) printed_check_repository: &'a Arc<PrintedCheckRepository>,
128 pub(crate) tax_tag_repair_run_service: &'a Arc<TaxTagRepairRunService>,
129 pub(crate) tax_tag_repair_run_repository: &'a Arc<TaxTagRepairRunRepository>,
130 pub(crate) financial_statement_service: &'a Arc<FinancialStatementService>,
131 pub(crate) financial_statement_repository: &'a Arc<FinancialStatementRepository>,
132 pub(crate) fiscal_period_service: &'a Arc<FiscalPeriodService>,
133 pub(crate) fiscal_period_repository: &'a Arc<FiscalPeriodRepository>,
134 pub(crate) journal_service: &'a Arc<JournalService>,
135 pub(crate) journal_repository: &'a Arc<JournalRepository>,
136 pub(crate) journal_line_service: &'a Arc<JournalLineService>,
137 pub(crate) journal_line_repository: &'a Arc<JournalLineRepository>,
138 pub(crate) ledger_service: &'a Arc<LedgerService>,
139 pub(crate) ledger_repository: &'a Arc<LedgerRepository>,
140 pub(crate) reconciliation_service: &'a Arc<ReconciliationService>,
141 pub(crate) reconciliation_repository: &'a Arc<ReconciliationRepository>,
142 pub(crate) reconciliation_item_service: &'a Arc<ReconciliationItemService>,
143 pub(crate) reconciliation_item_repository: &'a Arc<ReconciliationItemRepository>,
144 pub(crate) full_reconcile_service: &'a Arc<FullReconcileService>,
145 pub(crate) full_reconcile_repository: &'a Arc<FullReconcileRepository>,
146 pub(crate) partial_reconcile_service: &'a Arc<PartialReconcileService>,
147 pub(crate) partial_reconcile_repository: &'a Arc<PartialReconcileRepository>,
148}
149
150impl AccountingModule {
151 pub fn builder() -> AccountingModuleBuilder {
153 AccountingModuleBuilder::new()
154 }
155
156 pub fn all_crud_routes(&self) -> Router {
162 use presentation::http::{
163 create_account_routes,
164 create_accounting_post_routes,
165 create_cost_center_routes,
166 create_emv_qr_config_routes,
167 create_bank_check_sequence_routes,
168 create_printed_check_routes,
169 create_tax_tag_repair_run_routes,
170 create_financial_statement_routes,
171 create_fiscal_period_read_routes,
172 create_journal_routes,
173 create_journal_line_routes,
174 create_ledger_routes,
175 create_reconciliation_routes,
176 create_reconciliation_item_routes,
177 create_full_reconcile_routes,
178 create_partial_reconcile_routes,
179 };
180
181 Router::new()
182 .merge(create_account_routes(self.account_service.clone()))
183 .merge(create_accounting_post_routes(self.accounting_post_service.clone()))
184 .merge(create_cost_center_routes(self.cost_center_service.clone()))
185 .merge(create_emv_qr_config_routes(self.emv_qr_config_service.clone()))
186 .merge(create_bank_check_sequence_routes(self.bank_check_sequence_service.clone()))
187 .merge(create_printed_check_routes(self.printed_check_service.clone()))
188 .merge(create_tax_tag_repair_run_routes(self.tax_tag_repair_run_service.clone()))
189 .merge(create_financial_statement_routes(self.financial_statement_service.clone()))
190 .merge(create_fiscal_period_read_routes(self.fiscal_period_service.clone()))
194 .merge(create_journal_routes(self.journal_service.clone()))
195 .merge(create_journal_line_routes(self.journal_line_service.clone()))
196 .merge(create_ledger_routes(self.ledger_service.clone()))
197 .merge(create_reconciliation_routes(self.reconciliation_service.clone()))
198 .merge(create_reconciliation_item_routes(self.reconciliation_item_service.clone()))
199 .merge(create_full_reconcile_routes(self.full_reconcile_service.clone()))
200 .merge(create_partial_reconcile_routes(self.partial_reconcile_service.clone()))
201 }
202
203 #[deprecated(note = "mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface")]
209 pub fn routes(&self) -> Router {
210 self.all_crud_routes()
211 }
212
213 pub fn readonly_routes(&self) -> Router {
219 use presentation::http::{
220 create_account_read_routes,
221 create_accounting_post_read_routes,
222 create_cost_center_read_routes,
223 create_emv_qr_config_read_routes,
224 create_bank_check_sequence_read_routes,
225 create_printed_check_read_routes,
226 create_tax_tag_repair_run_read_routes,
227 create_financial_statement_read_routes,
228 create_fiscal_period_read_routes,
229 create_journal_read_routes,
230 create_journal_line_read_routes,
231 create_ledger_read_routes,
232 create_reconciliation_read_routes,
233 create_reconciliation_item_read_routes,
234 create_full_reconcile_read_routes,
235 create_partial_reconcile_read_routes,
236 };
237
238 Router::new()
239 .merge(create_account_read_routes(self.account_service.clone()))
240 .merge(create_accounting_post_read_routes(self.accounting_post_service.clone()))
241 .merge(create_cost_center_read_routes(self.cost_center_service.clone()))
242 .merge(create_emv_qr_config_read_routes(self.emv_qr_config_service.clone()))
243 .merge(create_bank_check_sequence_read_routes(self.bank_check_sequence_service.clone()))
244 .merge(create_printed_check_read_routes(self.printed_check_service.clone()))
245 .merge(create_tax_tag_repair_run_read_routes(self.tax_tag_repair_run_service.clone()))
246 .merge(create_financial_statement_read_routes(self.financial_statement_service.clone()))
247 .merge(create_fiscal_period_read_routes(self.fiscal_period_service.clone()))
248 .merge(create_journal_read_routes(self.journal_service.clone()))
249 .merge(create_journal_line_read_routes(self.journal_line_service.clone()))
250 .merge(create_ledger_read_routes(self.ledger_service.clone()))
251 .merge(create_reconciliation_read_routes(self.reconciliation_service.clone()))
252 .merge(create_reconciliation_item_read_routes(self.reconciliation_item_service.clone()))
253 .merge(create_full_reconcile_read_routes(self.full_reconcile_service.clone()))
254 .merge(create_partial_reconcile_read_routes(self.partial_reconcile_service.clone()))
255 }
256
257}
258
259pub struct AccountingModuleBuilder {
261 db_pool: Option<PgPool>,
262 ext: ModuleBuilderExt,
264}
265
266impl std::ops::Deref for AccountingModuleBuilder {
267 type Target = ModuleBuilderExt;
268 fn deref(&self) -> &Self::Target {
269 &self.ext
270 }
271}
272
273impl std::ops::DerefMut for AccountingModuleBuilder {
274 fn deref_mut(&mut self) -> &mut Self::Target {
275 &mut self.ext
276 }
277}
278
279impl AccountingModuleBuilder {
280 pub fn new() -> Self {
282 Self {
283 db_pool: None,
284 ext: Default::default(),
285 }
286 }
287
288 pub fn with_database(mut self, pool: PgPool) -> Self {
290 self.db_pool = Some(pool);
291 self
292 }
293
294
295 pub fn build(self) -> anyhow::Result<AccountingModule> {
297 let db_pool = self.db_pool
298 .ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;
299
300 let account_repository = Arc::new(AccountRepository::new(db_pool.clone()));
302 let account_service = Arc::new(crate::application::service::build_account_service(account_repository.clone()));
303
304 let accounting_post_repository = Arc::new(AccountingPostRepository::new(db_pool.clone()));
306 let accounting_post_service = Arc::new(crate::application::service::build_accounting_post_service(accounting_post_repository.clone()));
307
308 let cost_center_repository = Arc::new(CostCenterRepository::new(db_pool.clone()));
310 let cost_center_service = Arc::new(crate::application::service::build_cost_center_service(cost_center_repository.clone()));
311
312 let emv_qr_config_repository = Arc::new(EmvQrConfigRepository::new(db_pool.clone()));
314 let emv_qr_config_service = Arc::new(crate::application::service::build_emv_qr_config_service(emv_qr_config_repository.clone()));
315
316 let bank_check_sequence_repository = Arc::new(BankCheckSequenceRepository::new(db_pool.clone()));
318 let bank_check_sequence_service = Arc::new(crate::application::service::build_bank_check_sequence_service(bank_check_sequence_repository.clone()));
319
320 let printed_check_repository = Arc::new(PrintedCheckRepository::new(db_pool.clone()));
322 let printed_check_service = Arc::new(crate::application::service::build_printed_check_service(printed_check_repository.clone()));
323
324 let tax_tag_repair_run_repository = Arc::new(TaxTagRepairRunRepository::new(db_pool.clone()));
326 let tax_tag_repair_run_service = Arc::new(crate::application::service::build_tax_tag_repair_run_service(tax_tag_repair_run_repository.clone()));
327
328 let financial_statement_repository = Arc::new(FinancialStatementRepository::new(db_pool.clone()));
330 let financial_statement_service = Arc::new(crate::application::service::build_financial_statement_service(financial_statement_repository.clone()));
331
332 let fiscal_period_repository = Arc::new(FiscalPeriodRepository::new(db_pool.clone()));
334 let fiscal_period_service = Arc::new(crate::application::service::build_fiscal_period_service(fiscal_period_repository.clone()));
335
336 let journal_repository = Arc::new(JournalRepository::new(db_pool.clone()));
338 let journal_service = Arc::new(crate::application::service::build_journal_service(journal_repository.clone()));
339
340 let journal_line_repository = Arc::new(JournalLineRepository::new(db_pool.clone()));
342 let journal_line_service = Arc::new(crate::application::service::build_journal_line_service(journal_line_repository.clone()));
343
344 let ledger_repository = Arc::new(LedgerRepository::new(db_pool.clone()));
346 let ledger_service = Arc::new(crate::application::service::build_ledger_service(ledger_repository.clone()));
347
348 let reconciliation_repository = Arc::new(ReconciliationRepository::new(db_pool.clone()));
350 let reconciliation_service = Arc::new(crate::application::service::build_reconciliation_service(reconciliation_repository.clone()));
351
352 let reconciliation_item_repository = Arc::new(ReconciliationItemRepository::new(db_pool.clone()));
354 let reconciliation_item_service = Arc::new(crate::application::service::build_reconciliation_item_service(reconciliation_item_repository.clone()));
355
356 let full_reconcile_repository = Arc::new(FullReconcileRepository::new(db_pool.clone()));
358 let full_reconcile_service = Arc::new(crate::application::service::build_full_reconcile_service(full_reconcile_repository.clone()));
359
360 let partial_reconcile_repository = Arc::new(PartialReconcileRepository::new(db_pool.clone()));
362 let partial_reconcile_service = Arc::new(crate::application::service::build_partial_reconcile_service(partial_reconcile_repository.clone()));
363
364
365 let ext = self.ext.build(&ModuleParts {
367 db_pool: &db_pool,
368 account_service: &account_service,
369 account_repository: &account_repository,
370 accounting_post_service: &accounting_post_service,
371 accounting_post_repository: &accounting_post_repository,
372 cost_center_service: &cost_center_service,
373 cost_center_repository: &cost_center_repository,
374 emv_qr_config_service: &emv_qr_config_service,
375 emv_qr_config_repository: &emv_qr_config_repository,
376 bank_check_sequence_service: &bank_check_sequence_service,
377 bank_check_sequence_repository: &bank_check_sequence_repository,
378 printed_check_service: &printed_check_service,
379 printed_check_repository: &printed_check_repository,
380 tax_tag_repair_run_service: &tax_tag_repair_run_service,
381 tax_tag_repair_run_repository: &tax_tag_repair_run_repository,
382 financial_statement_service: &financial_statement_service,
383 financial_statement_repository: &financial_statement_repository,
384 fiscal_period_service: &fiscal_period_service,
385 fiscal_period_repository: &fiscal_period_repository,
386 journal_service: &journal_service,
387 journal_repository: &journal_repository,
388 journal_line_service: &journal_line_service,
389 journal_line_repository: &journal_line_repository,
390 ledger_service: &ledger_service,
391 ledger_repository: &ledger_repository,
392 reconciliation_service: &reconciliation_service,
393 reconciliation_repository: &reconciliation_repository,
394 reconciliation_item_service: &reconciliation_item_service,
395 reconciliation_item_repository: &reconciliation_item_repository,
396 full_reconcile_service: &full_reconcile_service,
397 full_reconcile_repository: &full_reconcile_repository,
398 partial_reconcile_service: &partial_reconcile_service,
399 partial_reconcile_repository: &partial_reconcile_repository,
400 })?;
401
402 Ok(AccountingModule {
403 account_service,
404 accounting_post_service,
405 cost_center_service,
406 emv_qr_config_service,
407 bank_check_sequence_service,
408 printed_check_service,
409 tax_tag_repair_run_service,
410 financial_statement_service,
411 fiscal_period_service,
412 journal_service,
413 journal_line_service,
414 ledger_service,
415 reconciliation_service,
416 reconciliation_item_service,
417 full_reconcile_service,
418 partial_reconcile_service,
419 ext,
420 })
421 }
422}
423
424impl Default for AccountingModuleBuilder {
425 fn default() -> Self {
426 Self::new()
427 }
428}