use super::{
card::{CardService, HttpCardService},
collection::{CollectionService, HttpCollectionService},
dashboard::{DashboardService, HttpDashboardService},
query::{HttpQueryService, QueryService},
};
use crate::repository::factory::{RepositoryConfig, RepositoryFactory};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct ServiceConfig {
pub repository_config: RepositoryConfig,
pub enable_validation: bool,
pub enable_business_rules: bool,
}
impl Default for ServiceConfig {
fn default() -> Self {
Self {
repository_config: RepositoryConfig::default(),
enable_validation: true,
enable_business_rules: true,
}
}
}
pub struct ServiceFactory {
_config: ServiceConfig,
repository_factory: RepositoryFactory,
}
impl ServiceFactory {
pub fn new(config: ServiceConfig) -> Self {
let repository_factory = RepositoryFactory::new(config.repository_config.clone());
Self {
_config: config,
repository_factory,
}
}
pub fn create_card_service(&self) -> Arc<dyn CardService> {
let repository = self.repository_factory.create_card_repository();
Arc::new(HttpCardService::new(repository))
}
pub fn create_dashboard_service(&self) -> Arc<dyn DashboardService> {
let repository = self.repository_factory.create_dashboard_repository();
Arc::new(HttpDashboardService::new(repository))
}
pub fn create_collection_service(&self) -> Arc<dyn CollectionService> {
let repository = self.repository_factory.create_collection_repository();
Arc::new(HttpCollectionService::new(repository))
}
pub fn create_query_service(&self) -> Arc<dyn QueryService> {
let repository = self.repository_factory.create_query_repository();
Arc::new(HttpQueryService::new(repository))
}
}