use crate::{Email, NythosResult, PasswordHash, TenantId, User, UserId, UserStatus};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NewUser {
email: Email,
}
impl NewUser {
pub fn new(email: Email) -> Self {
Self { email }
}
pub fn email(&self) -> &Email {
&self.email
}
pub fn into_email(self) -> Email {
self.email
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UserCredentials {
user: User,
password_hash: PasswordHash,
}
impl UserCredentials {
pub fn new(user: User, password_hash: PasswordHash) -> Self {
Self {
user,
password_hash,
}
}
pub fn user(&self) -> &User {
&self.user
}
pub fn password_hash(&self) -> &PasswordHash {
&self.password_hash
}
pub fn into_parts(self) -> (User, PasswordHash) {
(self.user, self.password_hash)
}
}
pub trait UserRepository {
async fn find_by_email(&self, tenant_id: TenantId, email: &Email)
-> NythosResult<Option<User>>;
async fn find_by_id(&self, tenant_id: TenantId, user_id: UserId) -> NythosResult<Option<User>>;
async fn find_credentials_by_email(
&self,
tenant_id: TenantId,
email: &Email,
) -> NythosResult<Option<UserCredentials>>;
async fn create(
&self,
tenant_id: TenantId,
new_user: NewUser,
password_hash: PasswordHash,
) -> NythosResult<User>;
async fn update_status(
&self,
tenant_id: TenantId,
user_id: UserId,
status: UserStatus,
) -> NythosResult<()>;
}