- Introduced `CreateTransactionInput`, `BulkCreateTransactionInput`, `UpdateTransactionInput`, and `TransactionFilter` structs for handling transaction creation and updates. - Added `BulkDeleteInput` and `BulkDeleteResult` structs for bulk deletion of transactions. - Created `TransactionStatistics` struct to encapsulate transaction statistics data. - Established a new module for transaction types in `mod.rs`. - Implemented `TransactionWithTags` struct in outputs for returning transactions with associated tags. - Updated `AppState` to include a transaction service, ensuring it is initialized and accessible.
50 lines
1.5 KiB
Rust
50 lines
1.5 KiB
Rust
use std::sync::Arc;
|
|
|
|
use sea_orm::DatabaseConnection;
|
|
|
|
use crate::errors::CommandResult;
|
|
|
|
pub mod accounts;
|
|
pub mod balance_calculator;
|
|
pub mod exchange_rate;
|
|
pub mod settings;
|
|
pub mod transactions;
|
|
|
|
#[async_trait::async_trait]
|
|
pub trait ServiceTrait: Send + Sync {
|
|
async fn on_app_start(&self) -> CommandResult<()> {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
/// Service factory for creating service instances
|
|
pub struct ServiceFactory;
|
|
|
|
pub struct ServiceFactoryResult {
|
|
pub account_service: Arc<dyn accounts::service::AccountService>,
|
|
pub transaction_service: Arc<dyn transactions::service::TransactionService>,
|
|
pub settings_service: Arc<dyn settings::service::SettingsService>,
|
|
pub exchange_rate_service: Arc<dyn exchange_rate::service::ExchangeRateService>,
|
|
}
|
|
|
|
impl ServiceFactory {
|
|
pub async fn create_services(db: DatabaseConnection) -> ServiceFactoryResult {
|
|
let account_service = Arc::new(accounts::service::AccountServiceImpl::new(db.clone()));
|
|
let transaction_service = Arc::new(transactions::service::TransactionServiceImpl::new(db.clone()));
|
|
let settings_service = Arc::new(settings::service::SettingsServiceImpl::new(db.clone()));
|
|
let exchange_rate_service = Arc::new(
|
|
exchange_rate::service::ExchangeRateServiceImpl::new(
|
|
db.clone(),
|
|
settings_service.clone(),
|
|
)
|
|
.await,
|
|
);
|
|
ServiceFactoryResult {
|
|
account_service,
|
|
transaction_service,
|
|
exchange_rate_service,
|
|
settings_service,
|
|
}
|
|
}
|
|
}
|