Skip to main content

koprogo_api/application/ports/
fund_repository.rs

1//! Port for persisting [`Fund`] entities and their [`FundReassignment`]
2//! audit trail (issue #635 — fonds affectés & thésaurisation, ADR-0054).
3//!
4//! All methods return `Result<_, AppError>` natively — no legacy `String`
5//! error debt to migrate later (CRITICAL.md #4 / #555).
6
7use crate::application::error::AppError;
8use crate::domain::entities::{Fund, FundReassignment};
9use async_trait::async_trait;
10use uuid::Uuid;
11
12#[async_trait]
13pub trait FundRepository: Send + Sync {
14    /// Persist a freshly created fund.
15    async fn create(&self, fund: &Fund) -> Result<Fund, AppError>;
16
17    /// Look up a fund by its primary key.
18    async fn find_by_id(&self, id: Uuid) -> Result<Option<Fund>, AppError>;
19
20    /// List all funds belonging to an ACP (all three natures combined).
21    async fn find_by_acp_id(&self, acp_id: Uuid) -> Result<Vec<Fund>, AppError>;
22
23    /// Persist balance/purpose changes (contribution, reassignment).
24    async fn update(&self, fund: &Fund) -> Result<Fund, AppError>;
25
26    /// Append a reassignment to the audit trail. Never mutated afterward
27    /// (append-only, like `SyndicResponse` — cf. `AppError::ResponseImmutable`
28    /// precedent).
29    async fn record_reassignment(&self, reassignment: &FundReassignment) -> Result<(), AppError>;
30
31    /// List the reassignment history of a fund, most recent first.
32    async fn list_reassignments(&self, fund_id: Uuid) -> Result<Vec<FundReassignment>, AppError>;
33}