koprogo_api/application/ports/
challenge_repository.rs1use crate::domain::entities::{Challenge, ChallengeProgress, ChallengeStatus};
2use async_trait::async_trait;
3use uuid::Uuid;
4
5#[async_trait]
7pub trait ChallengeRepository: Send + Sync {
8 async fn create(&self, challenge: &Challenge) -> Result<Challenge, String>;
10
11 async fn find_by_id(&self, id: Uuid) -> Result<Option<Challenge>, String>;
13
14 async fn find_by_organization(&self, organization_id: Uuid) -> Result<Vec<Challenge>, String>;
16
17 async fn find_by_organization_and_status(
19 &self,
20 organization_id: Uuid,
21 status: ChallengeStatus,
22 ) -> Result<Vec<Challenge>, String>;
23
24 async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<Challenge>, String>;
26
27 async fn find_active(&self, organization_id: Uuid) -> Result<Vec<Challenge>, String>;
29
30 async fn find_ended_not_completed(&self) -> Result<Vec<Challenge>, String>;
32
33 async fn update(&self, challenge: &Challenge) -> Result<Challenge, String>;
35
36 async fn delete(&self, id: Uuid) -> Result<(), String>;
38
39 async fn count_by_organization(&self, organization_id: Uuid) -> Result<i64, String>;
41}
42
43#[async_trait]
45pub trait ChallengeProgressRepository: Send + Sync {
46 async fn create(&self, progress: &ChallengeProgress) -> Result<ChallengeProgress, String>;
48
49 async fn find_by_id(&self, id: Uuid) -> Result<Option<ChallengeProgress>, String>;
51
52 async fn find_by_user_and_challenge(
54 &self,
55 user_id: Uuid,
56 challenge_id: Uuid,
57 ) -> Result<Option<ChallengeProgress>, String>;
58
59 async fn find_by_user(&self, user_id: Uuid) -> Result<Vec<ChallengeProgress>, String>;
61
62 async fn find_by_challenge(&self, challenge_id: Uuid)
64 -> Result<Vec<ChallengeProgress>, String>;
65
66 async fn find_active_by_user(&self, user_id: Uuid) -> Result<Vec<ChallengeProgress>, String>;
68
69 async fn update(&self, progress: &ChallengeProgress) -> Result<ChallengeProgress, String>;
71
72 async fn count_completed_by_user(&self, user_id: Uuid) -> Result<i64, String>;
74
75 async fn get_leaderboard(
77 &self,
78 organization_id: Uuid,
79 building_id: Option<Uuid>,
80 limit: i64,
81 ) -> Result<Vec<(Uuid, i32)>, String>; }