puerto 0.13.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.
{% if is_crud %}use business::domain::shared::pagination::Page;
{% endif %}use business::domain::{{ snake }}::model::{{ pascal }};
use poem_openapi::Object;
use uuid::Uuid;{% for import in imports %}
use {{ import }};{% endfor %}

#[derive(Debug, Object)]
#[oai(rename_all = "camelCase")]
pub struct {{ pascal }}Dto {
    pub id: Uuid,
{% for f in fields %}    pub {{ f.name }}: {{ f.field_type }},
{% endfor %}}

impl {{ pascal }}Dto {
    pub fn from_domain(entity: &{{ pascal }}) -> Self {
        Self {
            id: entity.id.value(),
{% for f in fields %}            {{ f.name }}: {{ f.accessor }},
{% endfor %}        }
    }
}

#[derive(Debug, Object)]
#[oai(rename_all = "camelCase")]
pub struct Create{{ pascal }}Request {
{% for f in fields %}    pub {{ f.name }}: {{ f.field_type }},
{% endfor %}}
{% if is_crud %}

/// One page of {{ plural_pascal }}: `total` counts them all, `limit` is the one the API applied.
#[derive(Debug, Object)]
#[oai(rename_all = "camelCase")]
pub struct {{ pascal }}PageDto {
    pub items: Vec<{{ pascal }}Dto>,
    pub total: u64,
    pub limit: u32,
    pub offset: u32,
}

impl {{ pascal }}PageDto {
    pub fn from_domain(page: &Page<{{ pascal }}>) -> Self {
        Self {
            items: page.items.iter().map({{ pascal }}Dto::from_domain).collect(),
            total: page.total,
            limit: page.limit,
            offset: page.offset,
        }
    }
}

#[derive(Debug, Object)]
#[oai(rename_all = "camelCase")]
pub struct Update{{ pascal }}Request {
{% for f in fields %}    pub {{ f.name }}: {{ f.field_type }},
{% endfor %}}
{% endif %}