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 where AC: AccountCategoryService + ?Sized, A: AccountsService + ?Sized, T: TransactionService + ?Sized, TC: CategoryService + ?Sized, TT: TagService + ?Sized, { pub account_category: Arc, pub accounts: Arc, pub transaction: Arc, pub transaction_category: Arc, pub transaction_tag: Arc, } pub fn create_services(db: DatabaseConnection) -> AppState { let account_category_service: Arc = Arc::new(AccountCategoryServiceImpl::new(db.clone())); let account_service: Arc = Arc::new(AccountsServiceImpl::new( db.clone(), Arc::new(AccountCategoryServiceImpl::new(db.clone())), )); let transaction_category_service: Arc = Arc::new(CategoryServiceImpl::new(db.clone())); let transaction_tag_service: Arc = 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, transaction_category: transaction_category_service, transaction_tag: transaction_tag_service, } }