puerto 0.19.0

Puerto — Rust full-stack DDD framework CLI. Scaffolds Clean Architecture projects with auto-wired DI, SQLx support, and zero manual wiring. Formerly puerto-framework.
use std::sync::Arc;

use async_trait::async_trait;

use crate::domain::{{ snake }}::{
    errors::{{ pascal }}Error,
    model::{{ pascal }},
    repository::{{ pascal }}RepositoryTrait,
{% if uow %}    unit_of_work::{{ pascal }}UnitOfWorkFactory,
{% endif %}    use_cases::{{ uc }}::{{ "{" }}{{ uc_pascal }}Params, {{ uc_pascal }}UseCaseTrait},
};

pub struct {{ uc_pascal }}UseCaseImpl {
    pub repository: Arc<dyn {{ pascal }}RepositoryTrait>,
{% if uow %}    /// Writes go through the unit of work: `begin`, `save`, `record` an event, `commit`. The
    /// repository only reads.
    pub uow_factory: Arc<dyn {{ pascal }}UnitOfWorkFactory>,
{% endif %}}

#[async_trait]
impl {{ uc_pascal }}UseCaseTrait for {{ uc_pascal }}UseCaseImpl {
    async fn execute(&self, _params: {{ uc_pascal }}Params) -> Result<{{ pascal }}, {{ pascal }}Error> {
        // Log what identifies the work, never the params themselves: they are user data.
        tracing::info!("{{ uc }}: start");
        todo!()
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::domain::{{ snake }}::repository::mocks::Mock{{ pascal }}Repository;
{% if uow %}    use crate::domain::{{ snake }}::unit_of_work::mocks::RecordingUnitOfWorkFactory;
{% endif %}

    #[tokio::test]
    #[ignore = "write this test"]
    async fn should_{{ uc }}_when_valid() {
        // Arrange
        let mock_repo = Mock{{ pascal }}Repository::new();
        let use_case = {{ uc_pascal }}UseCaseImpl {
            repository: Arc::new(mock_repo),
{% if uow %}            uow_factory: Arc::new(RecordingUnitOfWorkFactory::new()),
{% endif %}        };

        // Act
        let _ = &use_case;

        // Assert
        todo!("call use_case.execute(…) and assert on the outcome")
    }
}