koprogo_api/application/ports/
vote_repository.rs

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