From 54f973e349b7dac7ea7e34fa655073ae366062d1 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Tue, 31 Aug 2021 15:57:01 +0200 Subject: [PATCH] model: remove CreateGroupRequest --- model/src/lib.rs | 5 ----- src/domain/handler.rs | 6 +++--- src/domain/sql_backend_handler.rs | 13 ++++--------- src/infra/tcp_backend_handler.rs | 2 +- src/main.rs | 4 +--- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/model/src/lib.rs b/model/src/lib.rs index f9d1429..1570574 100644 --- a/model/src/lib.rs +++ b/model/src/lib.rs @@ -98,11 +98,6 @@ pub struct Group { pub users: Vec, } -#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] -pub struct CreateGroupRequest { - pub display_name: String, -} - #[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] pub struct AddUserToGroupRequest { pub user_id: String, diff --git a/src/domain/handler.rs b/src/domain/handler.rs index 0cb591f..6fd661c 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, Group, User}; +pub use lldap_model::{AddUserToGroupRequest, Group, User}; #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] pub struct BindRequest { @@ -41,7 +41,7 @@ pub trait BackendHandler: Clone + Send { async fn get_user_details(&self, user_id: &str) -> Result; async fn create_user(&self, request: CreateUserRequest) -> Result<()>; async fn delete_user(&self, user_id: &str) -> Result<()>; - async fn create_group(&self, request: CreateGroupRequest) -> Result; + async fn create_group(&self, group_name: &str) -> Result; async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>; async fn get_user_groups(&self, user: &str) -> Result>; } @@ -59,7 +59,7 @@ mockall::mock! { async fn get_user_details(&self, user_id: &str) -> Result; async fn create_user(&self, request: CreateUserRequest) -> Result<()>; async fn delete_user(&self, user_id: &str) -> Result<()>; - async fn create_group(&self, request: CreateGroupRequest) -> Result; + async fn create_group(&self, group_name: &str) -> 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 fa46a24..f234cb2 100644 --- a/src/domain/sql_backend_handler.rs +++ b/src/domain/sql_backend_handler.rs @@ -202,17 +202,17 @@ impl BackendHandler for SqlBackendHandler { Ok(()) } - async fn create_group(&self, request: CreateGroupRequest) -> Result { + async fn create_group(&self, group_name: &str) -> Result { let query = Query::insert() .into_table(Groups::Table) .columns(vec![Groups::DisplayName]) - .values_panic(vec![request.display_name.as_str().into()]) + .values_panic(vec![group_name.into()]) .to_string(DbQueryBuilder {}); sqlx::query(&query).execute(&self.sql_pool).await?; let query = Query::select() .column(Groups::GroupId) .from(Groups::Table) - .and_where(Expr::col(Groups::DisplayName).eq(request.display_name.as_str())) + .and_where(Expr::col(Groups::DisplayName).eq(group_name)) .to_string(DbQueryBuilder {}); let row = sqlx::query(&query).fetch_one(&self.sql_pool).await?; Ok(row.get::(&*Groups::GroupId.to_string())) @@ -293,12 +293,7 @@ mod tests { } async fn insert_group(handler: &SqlBackendHandler, name: &str) -> i32 { - handler - .create_group(CreateGroupRequest { - display_name: name.to_string(), - }) - .await - .unwrap() + handler.create_group(name).await.unwrap() } async fn insert_membership(handler: &SqlBackendHandler, group_id: i32, user_id: &str) { diff --git a/src/infra/tcp_backend_handler.rs b/src/infra/tcp_backend_handler.rs index 448bb74..fbf24b2 100644 --- a/src/infra/tcp_backend_handler.rs +++ b/src/infra/tcp_backend_handler.rs @@ -32,7 +32,7 @@ mockall::mock! { async fn get_user_groups(&self, user: &str) -> DomainResult>; async fn create_user(&self, request: CreateUserRequest) -> DomainResult<()>; async fn delete_user(&self, user_id: &str) -> DomainResult<()>; - async fn create_group(&self, request: CreateGroupRequest) -> DomainResult; + async fn create_group(&self, group_name: &str) -> DomainResult; async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> DomainResult<()>; } #[async_trait] diff --git a/src/main.rs b/src/main.rs index 9000166..13c33bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,9 +28,7 @@ async fn create_admin_user(handler: &SqlBackendHandler, config: &Configuration) .await .context("Error creating admin user")?; let admin_group_id = handler - .create_group(lldap_model::CreateGroupRequest { - display_name: "lldap_admin".to_string(), - }) + .create_group("lldap_admin") .await .context("Error creating admin group")?; handler