#![recursion_limit = "1024"]
#![allow(unused_imports)]
pub mod domain;
pub mod infrastructure;
pub mod application;
pub mod presentation;
pub mod seeders;
pub mod exports;
#[path = "lib.ext.rs"]
mod lib_ext;
pub use lib_ext::*;
#[allow(dead_code)]
pub(crate) type ThisModule = IntegrationsModule;
#[allow(dead_code)]
pub(crate) type ThisModuleBuilder = IntegrationsModuleBuilder;
pub use infrastructure::persistence::*;
pub use application::service::IntegrationConnectorService;
pub use application::service::IntegrationAccountService;
pub use application::service::IntegrationEventService;
pub use application::workflows::*;
use std::sync::Arc;
use axum::Router;
use sqlx::PgPool;
pub struct IntegrationsModule {
pub(crate) integration_connector_service: Arc<IntegrationConnectorService>,
#[allow(dead_code)]
pub(crate) integration_account_service: Arc<IntegrationAccountService>,
pub(crate) integration_event_service: Arc<IntegrationEventService>,
pub(crate) ext: ModuleExt,
}
impl std::ops::Deref for IntegrationsModule {
type Target = ModuleExt;
fn deref(&self) -> &Self::Target {
&self.ext
}
}
impl std::ops::DerefMut for IntegrationsModule {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.ext
}
}
#[allow(dead_code)]
pub(crate) struct ModuleParts<'a> {
pub(crate) db_pool: &'a PgPool,
pub(crate) integration_connector_service: &'a Arc<IntegrationConnectorService>,
pub(crate) integration_connector_repository: &'a Arc<IntegrationConnectorRepository>,
pub(crate) integration_account_service: &'a Arc<IntegrationAccountService>,
pub(crate) integration_account_repository: &'a Arc<IntegrationAccountRepository>,
pub(crate) integration_event_service: &'a Arc<IntegrationEventService>,
pub(crate) integration_event_repository: &'a Arc<IntegrationEventRepository>,
}
impl IntegrationsModule {
pub fn builder() -> IntegrationsModuleBuilder {
IntegrationsModuleBuilder::new()
}
pub fn all_crud_routes(&self) -> Router {
use presentation::http::{
create_integration_connector_routes,
create_integration_event_routes,
};
Router::new()
.merge(create_integration_connector_routes(self.integration_connector_service.clone()))
.merge(create_integration_event_routes(self.integration_event_service.clone()))
}
#[deprecated(note = "mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface")]
pub fn routes(&self) -> Router {
self.all_crud_routes()
}
pub fn readonly_routes(&self) -> Router {
use presentation::http::{
create_integration_connector_read_routes,
create_integration_event_read_routes,
};
Router::new()
.merge(create_integration_connector_read_routes(self.integration_connector_service.clone()))
.merge(create_integration_event_read_routes(self.integration_event_service.clone()))
}
}
pub struct IntegrationsModuleBuilder {
db_pool: Option<PgPool>,
ext: ModuleBuilderExt,
}
impl std::ops::Deref for IntegrationsModuleBuilder {
type Target = ModuleBuilderExt;
fn deref(&self) -> &Self::Target {
&self.ext
}
}
impl std::ops::DerefMut for IntegrationsModuleBuilder {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.ext
}
}
impl IntegrationsModuleBuilder {
pub fn new() -> Self {
Self {
db_pool: None,
ext: Default::default(),
}
}
pub fn with_database(mut self, pool: PgPool) -> Self {
self.db_pool = Some(pool);
self
}
pub fn build(self) -> anyhow::Result<IntegrationsModule> {
let db_pool = self.db_pool
.ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;
let integration_connector_repository = Arc::new(IntegrationConnectorRepository::new(db_pool.clone()));
let integration_connector_service = Arc::new(IntegrationConnectorService::with_repository(integration_connector_repository.clone()).with_guard(Arc::new(crate::application::service::IntegrationConnectorRowRules)));
let integration_account_repository = Arc::new(IntegrationAccountRepository::new(db_pool.clone()));
let integration_account_service = Arc::new(IntegrationAccountService::with_repository(integration_account_repository.clone()).with_guard(Arc::new(crate::application::service::IntegrationAccountRowRules)));
let integration_event_repository = Arc::new(IntegrationEventRepository::new(db_pool.clone()));
let integration_event_service = Arc::new(IntegrationEventService::with_repository(integration_event_repository.clone()).with_guard(Arc::new(crate::application::service::IntegrationEventRowRules)));
let ext = self.ext.build(&ModuleParts {
db_pool: &db_pool,
integration_connector_service: &integration_connector_service,
integration_connector_repository: &integration_connector_repository,
integration_account_service: &integration_account_service,
integration_account_repository: &integration_account_repository,
integration_event_service: &integration_event_service,
integration_event_repository: &integration_event_repository,
})?;
Ok(IntegrationsModule {
integration_connector_service,
integration_account_service,
integration_event_service,
ext,
})
}
}
impl Default for IntegrationsModuleBuilder {
fn default() -> Self {
Self::new()
}
}
include!("mod.ext.rs");