67 lines
2.0 KiB
Rust
67 lines
2.0 KiB
Rust
use std::sync::Arc;
|
|
|
|
use sea_orm::DatabaseConnection;
|
|
|
|
use crate::services::{
|
|
accounts::{
|
|
AccountsService, AccountsServiceImpl,
|
|
category::{AccountCategoryService, AccountCategoryServiceImpl},
|
|
},
|
|
transaction::{
|
|
TransactionService, TransactionServiceImpl,
|
|
category::{CategoryService, CategoryServiceImpl},
|
|
tag::{TagService, TagServiceImpl},
|
|
},
|
|
};
|
|
|
|
pub mod accounts;
|
|
pub mod transaction;
|
|
|
|
pub type AppState = Services<
|
|
dyn AccountCategoryService,
|
|
dyn AccountsService,
|
|
dyn TransactionService,
|
|
dyn CategoryService,
|
|
dyn TagService,
|
|
>;
|
|
|
|
#[derive(Clone)]
|
|
pub struct Services<AC, A, T, TC, TT>
|
|
where
|
|
AC: AccountCategoryService + ?Sized,
|
|
A: AccountsService + ?Sized,
|
|
T: TransactionService + ?Sized,
|
|
TC: CategoryService + ?Sized,
|
|
TT: TagService + ?Sized,
|
|
{
|
|
pub account_category: Arc<AC>,
|
|
pub accounts: Arc<A>,
|
|
pub transaction: Arc<T>,
|
|
pub transaction_category: Arc<TC>,
|
|
pub transaction_tag: Arc<TT>,
|
|
}
|
|
|
|
pub fn create_services(db: DatabaseConnection) -> AppState {
|
|
let account_category_service: Arc<dyn AccountCategoryService> =
|
|
Arc::new(AccountCategoryServiceImpl::new(db.clone()));
|
|
let account_service: Arc<dyn AccountsService> = Arc::new(AccountsServiceImpl::new(
|
|
db.clone(),
|
|
Arc::new(AccountCategoryServiceImpl::new(db.clone())),
|
|
));
|
|
let transaction_category_service: Arc<dyn CategoryService> =
|
|
Arc::new(CategoryServiceImpl::new(db.clone()));
|
|
let transaction_tag_service: Arc<dyn TagService> = Arc::new(TagServiceImpl::new(db.clone()));
|
|
Services {
|
|
account_category: account_category_service.clone(),
|
|
accounts: account_service.clone(),
|
|
transaction: Arc::new(TransactionServiceImpl::new(
|
|
db.clone(),
|
|
account_service.clone(),
|
|
transaction_category_service.clone(),
|
|
transaction_tag_service.clone(),
|
|
)) as Arc<dyn TransactionService>,
|
|
transaction_category: transaction_category_service,
|
|
transaction_tag: transaction_tag_service,
|
|
}
|
|
}
|