puerto 0.17.1

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 async_trait::async_trait;
use puerto_core::{Page, PageRequest, RepositoryError};

use super::model::{{ "{" }}{{ pascal }}, {{ pascal }}Id};

#[async_trait]
pub trait {{ pascal }}RepositoryTrait: Send + Sync {
    async fn find_all(&self, page: PageRequest) -> Result<Page<{{ pascal }}>, RepositoryError>;
    async fn find_by_id(&self, id: {{ pascal }}Id) -> Result<Option<{{ pascal }}>, RepositoryError>;
{% if events %}    // No `save`: writes go through `{{ pascal }}UnitOfWorkFactory`, which records their events.
{% else %}    async fn save(&self, entity: &{{ pascal }}) -> Result<(), RepositoryError>;
{% endif %}}

#[cfg(any(test, feature = "test-utils"))]
pub mod mocks {
    use mockall::mock;

    use super::*;

    mock! {
        pub {{ pascal }}Repository {}

        #[async_trait]
        impl {{ pascal }}RepositoryTrait for {{ pascal }}Repository {
            async fn find_all(&self, page: PageRequest) -> Result<Page<{{ pascal }}>, RepositoryError>;
            async fn find_by_id(&self, id: {{ pascal }}Id) -> Result<Option<{{ pascal }}>, RepositoryError>;
{% if not events %}            async fn save(&self, entity: &{{ pascal }}) -> Result<(), RepositoryError>;
{% endif %}        }
    }
}