backbone-accounting 0.18.1

GL, journals, ledger, reconciliation (extracted from bersihir)
Documentation
//! Application service for PartialReconcile entities
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Type alias over `GenericCrudService` — all CRUD logic lives in backbone-core.
//! For custom behaviour, create `partial_reconcile_service_custom.rs` (preserved on regen).

use backbone_core::GenericCrudService;

use crate::presentation::dto::{CreatePartialReconcileDto, UpdatePartialReconcileDto};
use crate::domain::entity::PartialReconcile;
use crate::infrastructure::persistence::PartialReconcileRepository;

/// Application service for PartialReconcile entities.
///
/// All 12 standard CRUD operations (list, create, get, update, patch,
/// soft_delete, restore, empty_trash, bulk_create, upsert, find_by_id,
/// list_deleted) are provided by `GenericCrudService`.
///
/// Custom extensions go in `partial_reconcile_service_custom.rs`:
///
/// ```rust,ignore
/// pub struct PartialReconcileServiceCustom {
///     inner: Arc<PartialReconcileService>,
///     // add domain-specific dependencies here
/// }
/// ```
pub type PartialReconcileService = GenericCrudService<
    PartialReconcile,
    CreatePartialReconcileDto,
    UpdatePartialReconcileDto,
    PartialReconcileRepository,
>;

/// The rules the schema declares for PartialReconcile, checked against the row a create or update
/// would store. The generated build attaches it to [`PartialReconcileService`]. A refusing rule's
/// break answers 422; a rule in shadow is logged under `backbone::write_guard` and the
/// write goes ahead.
pub struct PartialReconcileRowRules;

#[async_trait::async_trait]
impl backbone_core::write_guard::WriteGuard<PartialReconcile> for PartialReconcileRowRules {
    async fn check(
        &self,
        ctx: &backbone_core::write_guard::WriteCtx<'_, PartialReconcile>,
    ) -> backbone_core::write_guard::GuardOutcome {
        use backbone_core::row_rule as r;
        use backbone_core::violation::Violation;
        use backbone_core::write_guard::{GuardOutcome, WriteKind};
        let (create, update) = (ctx.kind == WriteKind::Create, ctx.kind == WriteKind::Update);
        let Some(after) = ctx.after.filter(|_| create || update) else {
            return GuardOutcome::allow();
        };
        let Ok(row) = serde_json::to_value(after) else {
            return GuardOutcome::allow();
        };
        let row = &row;
        let old = ctx.before.and_then(|b| serde_json::to_value(b).ok());
        let shadow = Vec::new();
        let mut refuse = Vec::new();
        // `debit_move_id_required` (@required on PartialReconcile.debit_move_id)
        if (create || (update && r::changed(old.as_ref(), row, &["debit_move_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "debit_move_id")), r::not(r::is_empty(r::trim(r::field(row, "debit_move_id")))))) {
            refuse.push(Violation::new("debit_move_id", "required", "debit_move_id is required"));
        }
        // `credit_move_id_required` (@required on PartialReconcile.credit_move_id)
        if (create || (update && r::changed(old.as_ref(), row, &["credit_move_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "credit_move_id")), r::not(r::is_empty(r::trim(r::field(row, "credit_move_id")))))) {
            refuse.push(Violation::new("credit_move_id", "required", "credit_move_id is required"));
        }
        // `amount_positive` (@positive on PartialReconcile.amount)
        if (create || (update && r::changed(old.as_ref(), row, &["amount"]))) && !r::holds(&r::gt(r::field(row, "amount"), r::Val::Num(0.0_f64))) {
            refuse.push(Violation::new("amount", "positive", "amount must be positive"));
        }
        // `debit_amount_currency_non_negative` (@non_negative on PartialReconcile.debit_amount_currency)
        if (create || (update && r::changed(old.as_ref(), row, &["debit_amount_currency"]))) && !r::holds(&r::ge(r::field(row, "debit_amount_currency"), r::Val::Num(0.0_f64))) {
            refuse.push(Violation::new("debit_amount_currency", "non_negative", "debit_amount_currency must not be negative"));
        }
        // `credit_amount_currency_non_negative` (@non_negative on PartialReconcile.credit_amount_currency)
        if (create || (update && r::changed(old.as_ref(), row, &["credit_amount_currency"]))) && !r::holds(&r::ge(r::field(row, "credit_amount_currency"), r::Val::Num(0.0_f64))) {
            refuse.push(Violation::new("credit_amount_currency", "non_negative", "credit_amount_currency must not be negative"));
        }
        // `currency_max_length` (@max(3) on PartialReconcile.currency)
        if (create || (update && r::changed(old.as_ref(), row, &["currency"]))) && !r::holds(&r::le(r::length(r::field(row, "currency")), r::Val::Num(3.0_f64))) {
            refuse.push(Violation::new("currency", "max_length", "currency must be at most 3 characters").with_param("max", 3_i64));
        }
        // `source_type_max_length` (@max(50) on PartialReconcile.source_type)
        if (create || (update && r::changed(old.as_ref(), row, &["source_type"]))) && !r::holds(&r::le(r::length(r::field(row, "source_type")), r::Val::Num(50.0_f64))) {
            refuse.push(Violation::new("source_type", "max_length", "source_type must be at most 50 characters").with_param("max", 50_i64));
        }
        GuardOutcome { refuse, shadow }
    }
}