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 delete(&self, id: Uuid) -> Result<bool, String>;
14    async fn count_by_organization(&self, org_id: Uuid) -> Result<i64, String>;
15}
16
17#[cfg(test)]
18pub use tests::MockUserRepo;
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23    use mockall::mock;
24
25    mock! {
26        pub UserRepo {}
27
28        #[async_trait]
29        impl UserRepository for UserRepo {
30            async fn create(&self, user: &User) -> Result<User, String>;
31            async fn find_by_id(&self, id: Uuid) -> Result<Option<User>, String>;
32            async fn find_by_email(&self, email: &str) -> Result<Option<User>, String>;
33            async fn find_all(&self) -> Result<Vec<User>, String>;
34            async fn find_by_organization(&self, org_id: Uuid) -> Result<Vec<User>, String>;
35            async fn update(&self, user: &User) -> Result<User, String>;
36            async fn delete(&self, id: Uuid) -> Result<bool, String>;
37            async fn count_by_organization(&self, org_id: Uuid) -> Result<i64, String>;
38        }
39    }
40}