backbone_integrations/
lib.rs1#![recursion_limit = "1024"]
18#![allow(unused_imports)]
19
20pub mod domain;
22pub mod infrastructure;
23pub mod application;
24pub mod presentation;
25pub mod seeders;
26pub mod exports;
27
28#[path = "lib.ext.rs"]
30mod lib_ext;
31pub use lib_ext::*;
32#[allow(dead_code)]
34pub(crate) type ThisModule = IntegrationsModule;
35#[allow(dead_code)]
36pub(crate) type ThisModuleBuilder = IntegrationsModuleBuilder;
37
38pub use infrastructure::persistence::*;
40
41pub use application::service::IntegrationConnectorService;
43pub use application::service::IntegrationAccountService;
44pub use application::service::IntegrationEventService;
45
46use std::sync::Arc;
47use axum::Router;
48use sqlx::PgPool;
49
50pub struct IntegrationsModule {
63 pub(crate) integration_connector_service: Arc<IntegrationConnectorService>,
64 #[allow(dead_code)]
65 pub(crate) integration_account_service: Arc<IntegrationAccountService>,
66 pub(crate) integration_event_service: Arc<IntegrationEventService>,
67 pub(crate) ext: ModuleExt,
69}
70
71impl std::ops::Deref for IntegrationsModule {
72 type Target = ModuleExt;
73 fn deref(&self) -> &Self::Target {
74 &self.ext
75 }
76}
77
78impl std::ops::DerefMut for IntegrationsModule {
79 fn deref_mut(&mut self) -> &mut Self::Target {
80 &mut self.ext
81 }
82}
83
84#[allow(dead_code)]
86pub(crate) struct ModuleParts<'a> {
87 pub(crate) db_pool: &'a PgPool,
88 pub(crate) integration_connector_service: &'a Arc<IntegrationConnectorService>,
89 pub(crate) integration_connector_repository: &'a Arc<IntegrationConnectorRepository>,
90 pub(crate) integration_account_service: &'a Arc<IntegrationAccountService>,
91 pub(crate) integration_account_repository: &'a Arc<IntegrationAccountRepository>,
92 pub(crate) integration_event_service: &'a Arc<IntegrationEventService>,
93 pub(crate) integration_event_repository: &'a Arc<IntegrationEventRepository>,
94}
95
96impl IntegrationsModule {
97 pub fn builder() -> IntegrationsModuleBuilder {
99 IntegrationsModuleBuilder::new()
100 }
101
102 pub fn all_crud_routes(&self) -> Router {
108 use presentation::http::{
109 create_integration_connector_routes,
110 create_integration_event_routes,
111 };
112
113 Router::new()
114 .merge(create_integration_connector_routes(self.integration_connector_service.clone()))
115 .merge(create_integration_event_routes(self.integration_event_service.clone()))
116 }
117
118 #[deprecated(note = "mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface")]
124 pub fn routes(&self) -> Router {
125 self.all_crud_routes()
126 }
127
128 pub fn readonly_routes(&self) -> Router {
134 use presentation::http::{
135 create_integration_connector_read_routes,
136 create_integration_event_read_routes,
137 };
138
139 Router::new()
140 .merge(create_integration_connector_read_routes(self.integration_connector_service.clone()))
141 .merge(create_integration_event_read_routes(self.integration_event_service.clone()))
142 }
143
144}
145
146pub struct IntegrationsModuleBuilder {
148 db_pool: Option<PgPool>,
149 ext: ModuleBuilderExt,
151}
152
153impl std::ops::Deref for IntegrationsModuleBuilder {
154 type Target = ModuleBuilderExt;
155 fn deref(&self) -> &Self::Target {
156 &self.ext
157 }
158}
159
160impl std::ops::DerefMut for IntegrationsModuleBuilder {
161 fn deref_mut(&mut self) -> &mut Self::Target {
162 &mut self.ext
163 }
164}
165
166impl IntegrationsModuleBuilder {
167 pub fn new() -> Self {
169 Self {
170 db_pool: None,
171 ext: Default::default(),
172 }
173 }
174
175 pub fn with_database(mut self, pool: PgPool) -> Self {
177 self.db_pool = Some(pool);
178 self
179 }
180
181
182 pub fn build(self) -> anyhow::Result<IntegrationsModule> {
184 let db_pool = self.db_pool
185 .ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;
186
187 let integration_connector_repository = Arc::new(IntegrationConnectorRepository::new(db_pool.clone()));
189 let integration_connector_service = Arc::new(IntegrationConnectorService::with_repository(integration_connector_repository.clone()).with_guard(Arc::new(crate::application::service::IntegrationConnectorRowRules)));
190
191 let integration_account_repository = Arc::new(IntegrationAccountRepository::new(db_pool.clone()));
193 let integration_account_service = Arc::new(IntegrationAccountService::with_repository(integration_account_repository.clone()).with_guard(Arc::new(crate::application::service::IntegrationAccountRowRules)));
194
195 let integration_event_repository = Arc::new(IntegrationEventRepository::new(db_pool.clone()));
197 let integration_event_service = Arc::new(IntegrationEventService::with_repository(integration_event_repository.clone()).with_guard(Arc::new(crate::application::service::IntegrationEventRowRules)));
198
199
200 let ext = self.ext.build(&ModuleParts {
202 db_pool: &db_pool,
203 integration_connector_service: &integration_connector_service,
204 integration_connector_repository: &integration_connector_repository,
205 integration_account_service: &integration_account_service,
206 integration_account_repository: &integration_account_repository,
207 integration_event_service: &integration_event_service,
208 integration_event_repository: &integration_event_repository,
209 })?;
210
211 Ok(IntegrationsModule {
212 integration_connector_service,
213 integration_account_service,
214 integration_event_service,
215 ext,
216 })
217 }
218}
219
220impl Default for IntegrationsModuleBuilder {
221 fn default() -> Self {
222 Self::new()
223 }
224}
225
226include!("mod.ext.rs");