Skip to main content

koprogo_api/application/ports/
vote_repository.rs

1use crate::domain::entities::Vote;
2use async_trait::async_trait;
3use rust_decimal::Decimal;
4use uuid::Uuid;
5
6/// Port (trait) for Vote repository operations
7#[async_trait]
8pub trait VoteRepository: Send + Sync {
9    /// Cast a vote on a resolution
10    async fn create(&self, vote: &Vote) -> Result<Vote, String>;
11
12    /// Find a vote by ID
13    async fn find_by_id(&self, id: Uuid) -> Result<Option<Vote>, String>;
14
15    /// Find all votes for a resolution
16    async fn find_by_resolution_id(&self, resolution_id: Uuid) -> Result<Vec<Vote>, String>;
17
18    /// Find all votes by an owner (across all resolutions)
19    async fn find_by_owner_id(&self, owner_id: Uuid) -> Result<Vec<Vote>, String>;
20
21    /// Find a vote for a specific unit on a specific resolution
22    async fn find_by_resolution_and_unit(
23        &self,
24        resolution_id: Uuid,
25        unit_id: Uuid,
26    ) -> Result<Option<Vote>, String>;
27
28    /// Check if a unit has already voted on a resolution
29    async fn has_voted(&self, resolution_id: Uuid, unit_id: Uuid) -> Result<bool, String>;
30
31    /// Update a vote (for changing vote choice)
32    async fn update(&self, vote: &Vote) -> Result<Vote, String>;
33
34    /// Delete a vote
35    async fn delete(&self, id: Uuid) -> Result<bool, String>;
36
37    /// Count votes for a resolution by choice
38    async fn count_by_resolution_and_choice(
39        &self,
40        resolution_id: Uuid,
41    ) -> Result<(i32, i32, i32), String>; // (pour, contre, abstention)
42
43    /// Get total voting power for a resolution by choice
44    async fn sum_voting_power_by_resolution(
45        &self,
46        resolution_id: Uuid,
47    ) -> Result<(Decimal, Decimal, Decimal), String>; // (pour, contre, abstention)
48
49    /// Count proxy votes held by a mandataire on a given resolution (Art. 3.87 ยง7 CC).
50    /// Returns (count_proxies, total_proxy_voting_power).
51    async fn count_proxy_votes_for_mandataire(
52        &self,
53        resolution_id: Uuid,
54        proxy_owner_id: Uuid,
55    ) -> Result<(i64, Decimal), String>;
56}