#![recursion_limit = "1024"]
#![allow(unused_imports)]
pub mod domain;
pub mod infrastructure;
pub mod application;
pub mod presentation;
pub mod seeders;
pub mod exports;
pub use domain::entity::*;
pub use infrastructure::persistence::*;
pub use application::service::ActivityService;
use std::sync::Arc;
use axum::Router;
use sqlx::PgPool;
pub struct ActivityModule {
pub(crate) activity_service: Arc<ActivityService>,
}
impl ActivityModule {
pub fn builder() -> ActivityModuleBuilder {
ActivityModuleBuilder::new()
}
pub fn all_crud_routes(&self) -> Router {
use presentation::http::{
create_activity_routes,
};
Router::new()
.merge(create_activity_routes(self.activity_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_activity_read_routes,
};
Router::new()
.merge(create_activity_read_routes(self.activity_service.clone()))
}
}
pub struct ActivityModuleBuilder {
db_pool: Option<PgPool>,
}
impl ActivityModuleBuilder {
pub fn new() -> Self {
Self {
db_pool: None,
}
}
pub fn with_database(mut self, pool: PgPool) -> Self {
self.db_pool = Some(pool);
self
}
pub fn build(self) -> anyhow::Result<ActivityModule> {
let db_pool = self.db_pool
.ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;
let activity_repository = Arc::new(ActivityRepository::new(db_pool.clone()));
let activity_service = Arc::new(ActivityService::with_repository(activity_repository.clone()).with_guard(Arc::new(crate::application::service::ActivityRowRules)));
Ok(ActivityModule {
activity_service,
})
}
}
impl Default for ActivityModuleBuilder {
fn default() -> Self {
Self::new()
}
}