diff --git a/model/src/lib.rs b/model/src/lib.rs index dad06de..f9d1429 100644 --- a/model/src/lib.rs +++ b/model/src/lib.rs @@ -92,11 +92,6 @@ impl Default for User { } } -#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)] -pub struct DeleteUserRequest { - pub user_id: String, -} - #[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] pub struct Group { pub display_name: String, diff --git a/src/domain/handler.rs b/src/domain/handler.rs index f1bef91..0cb591f 100644 --- a/src/domain/handler.rs +++ b/src/domain/handler.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use serde::{Deserialize, Serialize}; use std::collections::HashSet; -pub use lldap_model::{AddUserToGroupRequest, CreateGroupRequest, DeleteUserRequest, Group, User}; +pub use lldap_model::{AddUserToGroupRequest, CreateGroupRequest, Group, User}; #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] pub struct BindRequest { @@ -40,7 +40,7 @@ pub trait BackendHandler: Clone + Send { async fn list_groups(&self) -> Result>; async fn get_user_details(&self, user_id: &str) -> Result; async fn create_user(&self, request: CreateUserRequest) -> Result<()>; - async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>; + async fn delete_user(&self, user_id: &str) -> Result<()>; async fn create_group(&self, request: CreateGroupRequest) -> Result; async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>; async fn get_user_groups(&self, user: &str) -> Result>; @@ -58,7 +58,7 @@ mockall::mock! { async fn list_groups(&self) -> Result>; async fn get_user_details(&self, user_id: &str) -> Result; async fn create_user(&self, request: CreateUserRequest) -> Result<()>; - async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>; + async fn delete_user(&self, user_id: &str) -> Result<()>; async fn create_group(&self, request: CreateGroupRequest) -> Result; async fn get_user_groups(&self, user: &str) -> Result>; async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>; diff --git a/src/domain/sql_backend_handler.rs b/src/domain/sql_backend_handler.rs index 60913cd..fa46a24 100644 --- a/src/domain/sql_backend_handler.rs +++ b/src/domain/sql_backend_handler.rs @@ -193,10 +193,10 @@ impl BackendHandler for SqlBackendHandler { Ok(()) } - async fn delete_user(&self, request: DeleteUserRequest) -> Result<()> { + async fn delete_user(&self, user_id: &str) -> Result<()> { let delete_query = Query::delete() .from_table(Users::Table) - .and_where(Expr::col(Users::UserId).eq(request.user_id)) + .and_where(Expr::col(Users::UserId).eq(user_id)) .to_string(DbQueryBuilder {}); sqlx::query(&delete_query).execute(&self.sql_pool).await?; Ok(()) @@ -517,12 +517,7 @@ mod tests { insert_user(&handler, "Jennz", "boupBoup").await; // Remove a user - let _request_result = handler - .delete_user(DeleteUserRequest { - user_id: "Jennz".to_owned(), - }) - .await - .unwrap(); + let _request_result = handler.delete_user("Jennz").await.unwrap(); let users = handler .list_users(None) @@ -536,18 +531,8 @@ mod tests { // Insert new user and remove two insert_user(&handler, "NewBoi", "Joni").await; - let _request_result = handler - .delete_user(DeleteUserRequest { - user_id: "Hector".to_owned(), - }) - .await - .unwrap(); - let _request_result = handler - .delete_user(DeleteUserRequest { - user_id: "NewBoi".to_owned(), - }) - .await - .unwrap(); + let _request_result = handler.delete_user("Hector").await.unwrap(); + let _request_result = handler.delete_user("NewBoi").await.unwrap(); let users = handler .list_users(None) diff --git a/src/infra/tcp_backend_handler.rs b/src/infra/tcp_backend_handler.rs index 010ab44..448bb74 100644 --- a/src/infra/tcp_backend_handler.rs +++ b/src/infra/tcp_backend_handler.rs @@ -31,7 +31,7 @@ mockall::mock! { async fn get_user_details(&self, user_id: &str) -> DomainResult; async fn get_user_groups(&self, user: &str) -> DomainResult>; async fn create_user(&self, request: CreateUserRequest) -> DomainResult<()>; - async fn delete_user(&self, request: DeleteUserRequest) -> DomainResult<()>; + async fn delete_user(&self, user_id: &str) -> DomainResult<()>; async fn create_group(&self, request: CreateGroupRequest) -> DomainResult; async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> DomainResult<()>; }