Skip to main content

koprogo_api/application/ports/
resolution_repository.rs

1use crate::domain::entities::{Resolution, ResolutionStatus};
2use async_trait::async_trait;
3use rust_decimal::Decimal;
4use uuid::Uuid;
5
6/// Port (trait) for Resolution repository operations
7#[async_trait]
8pub trait ResolutionRepository: Send + Sync {
9    /// Create a new resolution
10    async fn create(&self, resolution: &Resolution) -> Result<Resolution, String>;
11
12    /// Find a resolution by ID
13    async fn find_by_id(&self, id: Uuid) -> Result<Option<Resolution>, String>;
14
15    /// Find all resolutions for a meeting
16    async fn find_by_meeting_id(&self, meeting_id: Uuid) -> Result<Vec<Resolution>, String>;
17
18    /// Find resolutions by status
19    async fn find_by_status(&self, status: ResolutionStatus) -> Result<Vec<Resolution>, String>;
20
21    /// Update a resolution (for vote counts and status changes)
22    async fn update(&self, resolution: &Resolution) -> Result<Resolution, String>;
23
24    /// Delete a resolution
25    async fn delete(&self, id: Uuid) -> Result<bool, String>;
26
27    /// Update vote counts for a resolution
28    async fn update_vote_counts(
29        &self,
30        resolution_id: Uuid,
31        vote_count_pour: i32,
32        vote_count_contre: i32,
33        vote_count_abstention: i32,
34        total_voting_power_pour: Decimal,
35        total_voting_power_contre: Decimal,
36        total_voting_power_abstention: Decimal,
37    ) -> Result<(), String>;
38
39    /// Close voting on a resolution and set final status
40    ///
41    /// `voix_plafonnees` consigne les écarts de l'Art. 3.87 § 7 al. 4 : pour
42    /// chaque votant ramené au poids des autres, ce dont il disposait et ce
43    /// qui lui a été retenu. `None` quand personne n'a été plafonné, ce qui
44    /// est le cas ordinaire.
45    ///
46    /// Le paramètre est dans cette signature et non dans une méthode à part :
47    /// clore un vote et consigner comment il a été décompté est un seul acte.
48    /// Les séparer laisserait exister un état où la résolution est close sans
49    /// que son décompte soit justifiable.
50    async fn close_voting(
51        &self,
52        resolution_id: Uuid,
53        final_status: ResolutionStatus,
54        voix_plafonnees: Option<serde_json::Value>,
55    ) -> Result<(), String>;
56
57    /// Get vote summary for all resolutions in a meeting
58    async fn get_meeting_vote_summary(&self, meeting_id: Uuid) -> Result<Vec<Resolution>, String>;
59}