koprogo_api/application/ports/
user_repository.rs

1use crate::domain::entities::User;
2use async_trait::async_trait;
3use uuid::Uuid;
4
5#[async_trait]
6pub trait UserRepository: Send + Sync {
7    async fn create(&self, user: &User) -> Result<User, String>;
8    async fn find_by_id(&self, id: Uuid) -> Result<Option<User>, String>;
9    async fn find_by_email(&self, email: &str) -> Result<Option<User>, String>;
10    async fn find_all(&self) -> Result<Vec<User>, String>;
11    async fn find_by_organization(&self, org_id: Uuid) -> Result<Vec<User>, String>;
12    async fn update(&self, user: &User) -> Result<User, String>;
13    async fn update_password(&self, id: Uuid, password_hash: &str) -> Result<bool, String>;
14    async fn activate(&self, id: Uuid) -> Result<Option<User>, String>;
15    async fn deactivate(&self, id: Uuid) -> Result<Option<User>, String>;
16    async fn delete(&self, id: Uuid) -> Result<bool, String>;
17    async fn count_by_organization(&self, org_id: Uuid) -> Result<i64, String>;
18}
19
20#[cfg(test)]
21pub use tests::MockUserRepo;
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26    use mockall::mock;
27
28    mock! {
29        pub UserRepo {}
30
31        #[async_trait]
32        impl UserRepository for UserRepo {
33            async fn create(&self, user: &User) -> Result<User, String>;
34            async fn find_by_id(&self, id: Uuid) -> Result<Option<User>, String>;
35            async fn find_by_email(&self, email: &str) -> Result<Option<User>, String>;
36            async fn find_all(&self) -> Result<Vec<User>, String>;
37            async fn find_by_organization(&self, org_id: Uuid) -> Result<Vec<User>, String>;
38            async fn update(&self, user: &User) -> Result<User, String>;
39            async fn update_password(&self, id: Uuid, password_hash: &str) -> Result<bool, String>;
40            async fn activate(&self, id: Uuid) -> Result<Option<User>, String>;
41            async fn deactivate(&self, id: Uuid) -> Result<Option<User>, String>;
42            async fn delete(&self, id: Uuid) -> Result<bool, String>;
43            async fn count_by_organization(&self, org_id: Uuid) -> Result<i64, String>;
44        }
45    }
46}