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;
27pub use domain::entity::*;
32
33pub use infrastructure::persistence::*;
35
36pub use application::service::IssueService;
38pub use application::service::ServiceLevelAgreementService;
39pub use application::service::ServiceLevelPriorityService;
40pub use application::service::WarrantyClaimService;
41
42use std::sync::Arc;
43use axum::Router;
44use sqlx::PgPool;
45
46pub struct SupportModule {
59 pub(crate) issue_service: Arc<IssueService>,
60 pub(crate) service_level_agreement_service: Arc<ServiceLevelAgreementService>,
61 pub(crate) service_level_priority_service: Arc<ServiceLevelPriorityService>,
62 pub(crate) warranty_claim_service: Arc<WarrantyClaimService>,
63 }
66
67impl SupportModule {
68 pub fn builder() -> SupportModuleBuilder {
70 SupportModuleBuilder::new()
71 }
72
73 pub fn all_crud_routes(&self) -> Router {
79 use presentation::http::{
80 create_issue_routes,
81 create_service_level_agreement_routes,
82 create_service_level_priority_routes,
83 create_warranty_claim_routes,
84 };
85
86 Router::new()
87 .merge(create_issue_routes(self.issue_service.clone()))
88 .merge(create_service_level_agreement_routes(self.service_level_agreement_service.clone()))
89 .merge(create_service_level_priority_routes(self.service_level_priority_service.clone()))
90 .merge(create_warranty_claim_routes(self.warranty_claim_service.clone()))
91 }
92
93 #[deprecated(note = "mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface")]
99 pub fn routes(&self) -> Router {
100 self.all_crud_routes()
101 }
102
103 pub fn readonly_routes(&self) -> Router {
109 use presentation::http::{
110 create_issue_read_routes,
111 create_service_level_agreement_read_routes,
112 create_service_level_priority_read_routes,
113 create_warranty_claim_read_routes,
114 };
115
116 Router::new()
117 .merge(create_issue_read_routes(self.issue_service.clone()))
118 .merge(create_service_level_agreement_read_routes(self.service_level_agreement_service.clone()))
119 .merge(create_service_level_priority_read_routes(self.service_level_priority_service.clone()))
120 .merge(create_warranty_claim_read_routes(self.warranty_claim_service.clone()))
121 }
122
123 }
126
127pub struct SupportModuleBuilder {
129 db_pool: Option<PgPool>,
130 }
133
134impl SupportModuleBuilder {
135 pub fn new() -> Self {
137 Self {
138 db_pool: None,
139 }
142 }
143
144 pub fn with_database(mut self, pool: PgPool) -> Self {
146 self.db_pool = Some(pool);
147 self
148 }
149
150 pub fn build(self) -> anyhow::Result<SupportModule> {
155 let db_pool = self.db_pool
156 .ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;
157
158 let issue_repository = Arc::new(IssueRepository::new(db_pool.clone()));
160 let issue_service = Arc::new(IssueService::with_repository(issue_repository.clone()));
161
162 let service_level_agreement_repository = Arc::new(ServiceLevelAgreementRepository::new(db_pool.clone()));
164 let service_level_agreement_service = Arc::new(ServiceLevelAgreementService::with_repository(service_level_agreement_repository.clone()));
165
166 let service_level_priority_repository = Arc::new(ServiceLevelPriorityRepository::new(db_pool.clone()));
168 let service_level_priority_service = Arc::new(ServiceLevelPriorityService::with_repository(service_level_priority_repository.clone()));
169
170 let warranty_claim_repository = Arc::new(WarrantyClaimRepository::new(db_pool.clone()));
172 let warranty_claim_service = Arc::new(WarrantyClaimService::with_repository(warranty_claim_repository.clone()));
173
174 Ok(SupportModule {
178 issue_service,
179 service_level_agreement_service,
180 service_level_priority_service,
181 warranty_claim_service,
182 })
185 }
186}
187
188impl Default for SupportModuleBuilder {
189 fn default() -> Self {
190 Self::new()
191 }
192}