koprogo_api/application/ports/
consent_repository.rs

1use crate::domain::entities::consent::{ConsentRecord, ConsentStatus};
2use async_trait::async_trait;
3use uuid::Uuid;
4
5/// Port (interface) for consent record repository
6/// Handles GDPR Art. 7 consent persistence and querying
7#[async_trait]
8pub trait ConsentRepository: Send + Sync {
9    /// Create a new consent record (append-only, immutable)
10    async fn create(&self, record: &ConsentRecord) -> Result<ConsentRecord, String>;
11
12    /// Find the latest consent of a given type for a user
13    async fn find_latest_by_user_and_type(
14        &self,
15        user_id: Uuid,
16        consent_type: &str,
17    ) -> Result<Option<ConsentRecord>, String>;
18
19    /// Find all consent records for a user (audit trail)
20    async fn find_all_by_user(&self, user_id: Uuid) -> Result<Vec<ConsentRecord>, String>;
21
22    /// Check if a user has accepted a specific consent type
23    async fn has_accepted(&self, user_id: Uuid, consent_type: &str) -> Result<bool, String>;
24
25    /// Build a consent status summary for a user
26    async fn get_consent_status(&self, user_id: Uuid) -> Result<ConsentStatus, String>;
27}