1#![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
28pub use domain::entity::*;
30
31pub use infrastructure::persistence::*;
33
34pub use application::service::IssueService;
36pub use application::service::ServiceLevelAgreementService;
37pub use application::service::ServiceLevelPriorityService;
38pub use application::service::WarrantyClaimService;
39
40use std::sync::Arc;
41use axum::Router;
42use sqlx::PgPool;
43
44pub struct SupportModule {
57 pub(crate) issue_service: Arc<IssueService>,
58 pub(crate) service_level_agreement_service: Arc<ServiceLevelAgreementService>,
59 pub(crate) service_level_priority_service: Arc<ServiceLevelPriorityService>,
60 pub(crate) warranty_claim_service: Arc<WarrantyClaimService>,
61 }
64
65impl SupportModule {
66 pub fn builder() -> SupportModuleBuilder {
68 SupportModuleBuilder::new()
69 }
70
71 pub fn all_crud_routes(&self) -> Router {
77 use presentation::http::{
78 create_issue_routes,
79 create_service_level_agreement_routes,
80 create_service_level_priority_routes,
81 create_warranty_claim_routes,
82 };
83
84 Router::new()
85 .merge(create_issue_routes(self.issue_service.clone()))
86 .merge(create_service_level_agreement_routes(self.service_level_agreement_service.clone()))
87 .merge(create_service_level_priority_routes(self.service_level_priority_service.clone()))
88 .merge(create_warranty_claim_routes(self.warranty_claim_service.clone()))
89 }
90
91 #[deprecated(note = "mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface")]
97 pub fn routes(&self) -> Router {
98 self.all_crud_routes()
99 }
100
101 pub fn readonly_routes(&self) -> Router {
107 use presentation::http::{
108 create_issue_read_routes,
109 create_service_level_agreement_read_routes,
110 create_service_level_priority_read_routes,
111 create_warranty_claim_read_routes,
112 };
113
114 Router::new()
115 .merge(create_issue_read_routes(self.issue_service.clone()))
116 .merge(create_service_level_agreement_read_routes(self.service_level_agreement_service.clone()))
117 .merge(create_service_level_priority_read_routes(self.service_level_priority_service.clone()))
118 .merge(create_warranty_claim_read_routes(self.warranty_claim_service.clone()))
119 }
120
121 }
124
125pub struct SupportModuleBuilder {
127 db_pool: Option<PgPool>,
128}
129
130impl SupportModuleBuilder {
131 pub fn new() -> Self {
133 Self {
134 db_pool: None,
135 }
136 }
137
138 pub fn with_database(mut self, pool: PgPool) -> Self {
140 self.db_pool = Some(pool);
141 self
142 }
143
144 pub fn build(self) -> anyhow::Result<SupportModule> {
149 let db_pool = self.db_pool
150 .ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;
151
152 let issue_repository = Arc::new(IssueRepository::new(db_pool.clone()));
154 let issue_service = Arc::new(IssueService::with_repository(issue_repository.clone()));
155
156 let service_level_agreement_repository = Arc::new(ServiceLevelAgreementRepository::new(db_pool.clone()));
158 let service_level_agreement_service = Arc::new(ServiceLevelAgreementService::with_repository(service_level_agreement_repository.clone()));
159
160 let service_level_priority_repository = Arc::new(ServiceLevelPriorityRepository::new(db_pool.clone()));
162 let service_level_priority_service = Arc::new(ServiceLevelPriorityService::with_repository(service_level_priority_repository.clone()));
163
164 let warranty_claim_repository = Arc::new(WarrantyClaimRepository::new(db_pool.clone()));
166 let warranty_claim_service = Arc::new(WarrantyClaimService::with_repository(warranty_claim_repository.clone()));
167
168 Ok(SupportModule {
172 issue_service,
173 service_level_agreement_service,
174 service_level_priority_service,
175 warranty_claim_service,
176 })
179 }
180}
181
182impl Default for SupportModuleBuilder {
183 fn default() -> Self {
184 Self::new()
185 }
186}