backbone-banking 0.7.1

Cash & bank — bank/account master, statement import, reconciliation, and clearing postings (5th GL producer)
Documentation
//! Banking Module Handlers
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This module provides:
//! - AppState dependency injection container
//! - Custom handler integration points

use std::sync::Arc;

// Import all services
use crate::application::service::BankService;
use crate::application::service::BankAccountService;
use crate::application::service::BankClearanceService;
use crate::application::service::BankReconciliationService;
use crate::application::service::BankStatementImportService;
use crate::application::service::BankTransactionService;
use crate::application::service::FxGainLossService;
use crate::application::service::ReconcilePresetService;

/// Application state for dependency injection.
///
/// This struct holds references to all module services
/// and is passed to HTTP handlers via Axum's State extractor.
///
/// # Example
///
/// ```ignore
/// use axum::extract::State;
///
/// async fn custom_handler(
///     State(state): State<AppState>,
/// ) -> impl IntoResponse {
///     // Access services via state
/// }
/// ```
#[derive(Clone)]
pub struct AppState {
    /// Bank service
    pub bank_service: Arc<BankService>,
    /// BankAccount service
    pub bank_account_service: Arc<BankAccountService>,
    /// BankClearance service
    pub bank_clearance_service: Arc<BankClearanceService>,
    /// BankReconciliation service
    pub bank_reconciliation_service: Arc<BankReconciliationService>,
    /// BankStatementImport service
    pub bank_statement_import_service: Arc<BankStatementImportService>,
    /// BankTransaction service
    pub bank_transaction_service: Arc<BankTransactionService>,
    /// FxGainLoss service
    pub fx_gain_loss_service: Arc<FxGainLossService>,
    /// ReconcilePreset service
    pub reconcile_preset_service: Arc<ReconcilePresetService>,
}

impl AppState {
    /// Create a new AppState with all services.
    pub fn new(
        bank_service: Arc<BankService>,
        bank_account_service: Arc<BankAccountService>,
        bank_clearance_service: Arc<BankClearanceService>,
        bank_reconciliation_service: Arc<BankReconciliationService>,
        bank_statement_import_service: Arc<BankStatementImportService>,
        bank_transaction_service: Arc<BankTransactionService>,
        fx_gain_loss_service: Arc<FxGainLossService>,
        reconcile_preset_service: Arc<ReconcilePresetService>
    ) -> Self {
        Self {
            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,
        }
    }

    /// Create AppState from module instance.
    pub fn from_module(module: &crate::BankingModule) -> Self {
        Self {
            bank_service: module.bank_service.clone(),
            bank_account_service: module.bank_account_service.clone(),
            bank_clearance_service: module.bank_clearance_service.clone(),
            bank_reconciliation_service: module.bank_reconciliation_service.clone(),
            bank_statement_import_service: module.bank_statement_import_service.clone(),
            bank_transaction_service: module.bank_transaction_service.clone(),
            fx_gain_loss_service: module.fx_gain_loss_service.clone(),
            reconcile_preset_service: module.reconcile_preset_service.clone(),
        }
    }
}

/// Builder for AppState.
///
/// Allows incremental construction of AppState.
#[derive(Default)]
pub struct AppStateBuilder {
    bank_service: Option<Arc<BankService>>,
    bank_account_service: Option<Arc<BankAccountService>>,
    bank_clearance_service: Option<Arc<BankClearanceService>>,
    bank_reconciliation_service: Option<Arc<BankReconciliationService>>,
    bank_statement_import_service: Option<Arc<BankStatementImportService>>,
    bank_transaction_service: Option<Arc<BankTransactionService>>,
    fx_gain_loss_service: Option<Arc<FxGainLossService>>,
    reconcile_preset_service: Option<Arc<ReconcilePresetService>>,
}

impl AppStateBuilder {
    /// Create a new builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the Bank service.
    pub fn with_bank_service(mut self, service: Arc<BankService>) -> Self {
        self.bank_service = Some(service);
        self
    }

    /// Set the BankAccount service.
    pub fn with_bank_account_service(mut self, service: Arc<BankAccountService>) -> Self {
        self.bank_account_service = Some(service);
        self
    }

    /// Set the BankClearance service.
    pub fn with_bank_clearance_service(mut self, service: Arc<BankClearanceService>) -> Self {
        self.bank_clearance_service = Some(service);
        self
    }

    /// Set the BankReconciliation service.
    pub fn with_bank_reconciliation_service(mut self, service: Arc<BankReconciliationService>) -> Self {
        self.bank_reconciliation_service = Some(service);
        self
    }

    /// Set the BankStatementImport service.
    pub fn with_bank_statement_import_service(mut self, service: Arc<BankStatementImportService>) -> Self {
        self.bank_statement_import_service = Some(service);
        self
    }

    /// Set the BankTransaction service.
    pub fn with_bank_transaction_service(mut self, service: Arc<BankTransactionService>) -> Self {
        self.bank_transaction_service = Some(service);
        self
    }

    /// Set the FxGainLoss service.
    pub fn with_fx_gain_loss_service(mut self, service: Arc<FxGainLossService>) -> Self {
        self.fx_gain_loss_service = Some(service);
        self
    }

    /// Set the ReconcilePreset service.
    pub fn with_reconcile_preset_service(mut self, service: Arc<ReconcilePresetService>) -> Self {
        self.reconcile_preset_service = Some(service);
        self
    }

    /// Build the AppState.
    ///
    /// # Panics
    ///
    /// Panics if any required service is not set.
    pub fn build(self) -> AppState {
        AppState {
            bank_service: self.bank_service.expect("bank_service is required"),
            bank_account_service: self.bank_account_service.expect("bank_account_service is required"),
            bank_clearance_service: self.bank_clearance_service.expect("bank_clearance_service is required"),
            bank_reconciliation_service: self.bank_reconciliation_service.expect("bank_reconciliation_service is required"),
            bank_statement_import_service: self.bank_statement_import_service.expect("bank_statement_import_service is required"),
            bank_transaction_service: self.bank_transaction_service.expect("bank_transaction_service is required"),
            fx_gain_loss_service: self.fx_gain_loss_service.expect("fx_gain_loss_service is required"),
            reconcile_preset_service: self.reconcile_preset_service.expect("reconcile_preset_service is required"),
        }
    }
}