koprogo_api/application/ports/
poll_repository.rs1use crate::application::dto::{PageRequest, PollFilters};
2use crate::domain::entities::Poll;
3use async_trait::async_trait;
4use serde::Serialize;
5use uuid::Uuid;
6
7#[async_trait]
8pub trait PollRepository: Send + Sync {
9 async fn create(&self, poll: &Poll) -> Result<Poll, String>;
10 async fn find_by_id(&self, id: Uuid) -> Result<Option<Poll>, String>;
11 async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<Poll>, String>;
12 async fn find_by_created_by(&self, created_by: Uuid) -> Result<Vec<Poll>, String>;
13
14 async fn find_all_paginated(
17 &self,
18 page_request: &PageRequest,
19 filters: &PollFilters,
20 ) -> Result<(Vec<Poll>, i64), String>;
21
22 async fn find_active(&self, building_id: Uuid) -> Result<Vec<Poll>, String>;
24
25 async fn find_by_status(&self, building_id: Uuid, status: &str) -> Result<Vec<Poll>, String>;
27
28 async fn find_expired_active(&self) -> Result<Vec<Poll>, String>;
30
31 async fn update(&self, poll: &Poll) -> Result<Poll, String>;
32 async fn delete(&self, id: Uuid) -> Result<bool, String>;
33
34 async fn get_building_statistics(&self, building_id: Uuid) -> Result<PollStatistics, String>;
36}
37
38#[derive(Debug, Clone, Serialize)]
39pub struct PollStatistics {
40 pub total_polls: i64,
41 pub active_polls: i64,
42 pub closed_polls: i64,
43 pub average_participation_rate: f64,
44}