diff --git a/src/identity/application/services/set_user_admin/command.rs b/src/identity/application/services/set_user_admin/command.rs index 587d6b2..5aaf715 100644 --- a/src/identity/application/services/set_user_admin/command.rs +++ b/src/identity/application/services/set_user_admin/command.rs @@ -40,6 +40,7 @@ mod tests { .hashed_password(username.into()) .is_verified(true) .is_admin(true) + .deleted(false) .build() .unwrap(), ) @@ -53,6 +54,7 @@ mod tests { .hashed_password(username.into()) .is_verified(true) .is_admin(false) + .deleted(false) .build() .unwrap(), ) diff --git a/src/identity/application/services/set_user_admin/mod.rs b/src/identity/application/services/set_user_admin/mod.rs index 8aa32f7..0676f01 100644 --- a/src/identity/application/services/set_user_admin/mod.rs +++ b/src/identity/application/services/set_user_admin/mod.rs @@ -9,10 +9,12 @@ pub mod service; use super::errors::*; #[async_trait::async_trait] -pub trait SetUserAdminUseCase { +pub trait SetUserAdminUseCase: Send + Sync { async fn set_user_admin( &self, cmd: command::SetAdminCommand, //) -> errors::ProcessAuthorizationServiceResult; ) -> events::UserPromotedToAdminEvent; } + +pub type SetUserAdminServiceObj = std::sync::Arc; diff --git a/src/identity/application/services/set_user_admin/service.rs b/src/identity/application/services/set_user_admin/service.rs index c3ac6aa..fdee643 100644 --- a/src/identity/application/services/set_user_admin/service.rs +++ b/src/identity/application/services/set_user_admin/service.rs @@ -34,6 +34,7 @@ mod tests { .hashed_password(username.into()) .is_verified(true) .is_admin(true) + .deleted(false) .build() .unwrap(); diff --git a/src/identity/domain/aggregate.rs b/src/identity/domain/aggregate.rs index 2b07605..39f6396 100644 --- a/src/identity/domain/aggregate.rs +++ b/src/identity/domain/aggregate.rs @@ -7,7 +7,7 @@ use derive_getters::Getters; use serde::{Deserialize, Serialize}; #[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 { username: String, @@ -15,4 +15,65 @@ pub struct User { hashed_password: String, is_verified: 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()); + } }