feat: identity: add deleted field to user

This commit is contained in:
Aravinth Manivannan 2024-05-19 00:34:22 +05:30
parent 434436b81f
commit cef61fe229
Signed by: realaravinth
GPG key ID: F8F50389936984FF
4 changed files with 68 additions and 2 deletions

View file

@ -40,6 +40,7 @@ mod tests {
.hashed_password(username.into()) .hashed_password(username.into())
.is_verified(true) .is_verified(true)
.is_admin(true) .is_admin(true)
.deleted(false)
.build() .build()
.unwrap(), .unwrap(),
) )
@ -53,6 +54,7 @@ mod tests {
.hashed_password(username.into()) .hashed_password(username.into())
.is_verified(true) .is_verified(true)
.is_admin(false) .is_admin(false)
.deleted(false)
.build() .build()
.unwrap(), .unwrap(),
) )

View file

@ -9,10 +9,12 @@ pub mod service;
use super::errors::*; use super::errors::*;
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait SetUserAdminUseCase { pub trait SetUserAdminUseCase: Send + Sync {
async fn set_user_admin( async fn set_user_admin(
&self, &self,
cmd: command::SetAdminCommand, cmd: command::SetAdminCommand,
//) -> errors::ProcessAuthorizationServiceResult<String>; //) -> errors::ProcessAuthorizationServiceResult<String>;
) -> events::UserPromotedToAdminEvent; ) -> events::UserPromotedToAdminEvent;
} }
pub type SetUserAdminServiceObj = std::sync::Arc<dyn SetUserAdminUseCase>;

View file

@ -34,6 +34,7 @@ mod tests {
.hashed_password(username.into()) .hashed_password(username.into())
.is_verified(true) .is_verified(true)
.is_admin(true) .is_admin(true)
.deleted(false)
.build() .build()
.unwrap(); .unwrap();

View file

@ -7,7 +7,7 @@ use derive_getters::Getters;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive( #[derive(
Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder, Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)] )]
pub struct User { pub struct User {
username: String, username: String,
@ -15,4 +15,65 @@ pub struct User {
hashed_password: String, hashed_password: String,
is_verified: bool, is_verified: bool,
is_admin: bool, is_admin: bool,
deleted: bool,
}
impl Default for User {
fn default() -> Self {
User {
username: "".to_string(),
email: "".to_string(),
hashed_password: "".to_string(),
is_verified: false,
is_admin: false,
deleted: false,
}
}
}
impl User {
pub fn set_email(&mut self, email: String) -> &mut Self {
self.email = email;
self
}
pub fn set_hashed_password(&mut self, hashed_password: String) -> &mut Self {
self.hashed_password = hashed_password;
self
}
pub fn set_is_verified(&mut self, is_verified: bool) -> &mut Self {
self.is_verified = is_verified;
self
}
pub fn set_is_admin(&mut self, is_admin: bool) -> &mut Self {
self.is_admin = is_admin;
self
}
pub fn set_deleted(&mut self, deleted: bool) -> &mut Self {
self.deleted = deleted;
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_setters() {
let mut u = User::default();
assert_eq!(u.set_email("foo".into()).email(), "foo");
assert_eq!(u.set_hashed_password("bar".into()).hashed_password(), "bar");
assert!(!u.is_verified());
assert!(u.set_is_verified(true).is_verified());
assert!(!u.is_admin());
assert!(u.set_is_admin(true).is_admin());
assert!(!u.deleted());
assert!(u.set_deleted(true).deleted());
}
} }