1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/// User persistence repository port.
///
/// Defines the abstract contract that SQL-backed (or any other)
/// user-store adapters must implement. Lives in `paladin-ports` so
/// `paladin-storage` can implement it without depending on the facade.
use async_trait::async_trait;
use paladin_core::platform::container::user::{User, UserError};
use uuid::Uuid;
/// Repository port for [`User`] persistence.
#[async_trait]
pub trait UserRepositoryPort: Send + Sync {
/// Find a user by their UUID.
async fn find_by_id(&self, id: Uuid) -> Result<Option<User>, UserError>;
/// Find a user by email address.
async fn find_by_email(&self, email: &str) -> Result<Option<User>, UserError>;
/// Find a user by username.
async fn find_by_username(&self, username: &str) -> Result<Option<User>, UserError>;
/// Persist a new user; returns the saved entity.
async fn save(&self, user: User) -> Result<User, UserError>;
/// Overwrite an existing user; returns the updated entity.
async fn update(&self, user: User) -> Result<User, UserError>;
/// Remove a user by UUID.
async fn delete(&self, id: Uuid) -> Result<(), UserError>;
/// Return `true` if the given email address is already taken.
async fn email_exists(&self, email: &str) -> Result<bool, UserError>;
/// Return `true` if the given username is already taken.
async fn username_exists(&self, username: &str) -> Result<bool, UserError>;
/// Return all users with the given active status.
async fn find_by_active_status(&self, is_active: bool) -> Result<Vec<User>, UserError>;
/// Return all users with the given verification status.
async fn find_by_verification_status(&self, is_verified: bool) -> Result<Vec<User>, UserError>;
/// Return the total number of stored users.
async fn count_users(&self) -> Result<u64, UserError>;
}