Skip to main content

made_core/ports/
deliberation_repository.rs

1//! [`DeliberationRepositoryPort`] — persistence for deliberations
2//! across process restarts / replicas.
3
4use async_trait::async_trait;
5
6use crate::entities::Deliberation;
7use crate::error::DomainError;
8use crate::value_objects::{AuthorizationEvidence, TaskId};
9
10#[async_trait]
11pub trait DeliberationRepositoryPort: Send + Sync {
12    /// Persist (or update) a deliberation keyed by its task id.
13    async fn save(&self, deliberation: &Deliberation) -> Result<(), DomainError>;
14    async fn save_authorized(
15        &self,
16        deliberation: &Deliberation,
17        authorization: Option<AuthorizationEvidence>,
18    ) -> Result<(), DomainError> {
19        if authorization.is_some() {
20            return Err(DomainError::InvariantViolated {
21                reason: "deliberation repository cannot persist authorization evidence",
22            });
23        }
24        self.save(deliberation).await
25    }
26
27    /// Fetch a deliberation by task id. Returns
28    /// [`DomainError::NotFound`] when absent.
29    async fn get(&self, task_id: &TaskId) -> Result<Deliberation, DomainError>;
30
31    /// Cheap existence check.
32    async fn exists(&self, task_id: &TaskId) -> Result<bool, DomainError>;
33}