backbone-activity 0.5.0

Sales activity / touchpoints + rep tasks — the substrate lead/deal sit on
Documentation
//! Activity Module Handlers
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This module provides:
//! - AppState dependency injection container
//! - Custom handler integration points

use std::sync::Arc;

// Import all services
use crate::application::service::ActivityService;

/// Application state for dependency injection.
///
/// This struct holds references to all module services
/// and is passed to HTTP handlers via Axum's State extractor.
///
/// # Example
///
/// ```ignore
/// use axum::extract::State;
///
/// async fn custom_handler(
///     State(state): State<AppState>,
/// ) -> impl IntoResponse {
///     // Access services via state
/// }
/// ```
#[derive(Clone)]
pub struct AppState {
    /// Activity service
    pub activity_service: Arc<ActivityService>,
}

impl AppState {
    /// Create a new AppState with all services.
    pub fn new(
        activity_service: Arc<ActivityService>
    ) -> Self {
        Self {
            activity_service,
        }
    }

    /// Create AppState from module instance.
    pub fn from_module(module: &crate::ActivityModule) -> Self {
        Self {
            activity_service: module.activity_service.clone(),
        }
    }
}

/// Builder for AppState.
///
/// Allows incremental construction of AppState.
#[derive(Default)]
pub struct AppStateBuilder {
    activity_service: Option<Arc<ActivityService>>,
}

impl AppStateBuilder {
    /// Create a new builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the Activity service.
    pub fn with_activity_service(mut self, service: Arc<ActivityService>) -> Self {
        self.activity_service = Some(service);
        self
    }

    /// Build the AppState.
    ///
    /// # Panics
    ///
    /// Panics if any required service is not set.
    pub fn build(self) -> AppState {
        AppState {
            activity_service: self.activity_service.expect("activity_service is required"),
        }
    }
}