diff --git a/model/src/lib.rs b/model/src/lib.rs index c078495..5041042 100644 --- a/model/src/lib.rs +++ b/model/src/lib.rs @@ -67,11 +67,6 @@ pub mod registration { } } -#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] -pub struct UserDetailsRequest { - pub user_id: String, -} - #[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] #[cfg_attr(not(target_arch = "wasm32"), derive(sqlx::FromRow))] pub struct User { diff --git a/src/domain/handler.rs b/src/domain/handler.rs index 55edc45..875e180 100644 --- a/src/domain/handler.rs +++ b/src/domain/handler.rs @@ -5,7 +5,6 @@ use std::collections::HashSet; pub use lldap_model::{ AddUserToGroupRequest, CreateGroupRequest, CreateUserRequest, DeleteUserRequest, Group, User, - UserDetailsRequest, }; #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] @@ -31,7 +30,7 @@ pub trait LoginHandler: Clone + Send { pub trait BackendHandler: Clone + Send { async fn list_users(&self, filters: Option) -> Result>; async fn list_groups(&self) -> Result>; - async fn get_user_details(&self, request: UserDetailsRequest) -> 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 create_group(&self, request: CreateGroupRequest) -> Result; @@ -49,7 +48,7 @@ mockall::mock! { impl BackendHandler for TestBackendHandler { async fn list_users(&self, filters: Option) -> Result>; async fn list_groups(&self) -> Result>; - async fn get_user_details(&self, request: UserDetailsRequest) -> 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 create_group(&self, request: CreateGroupRequest) -> Result; diff --git a/src/domain/sql_backend_handler.rs b/src/domain/sql_backend_handler.rs index e4f6a14..60913cd 100644 --- a/src/domain/sql_backend_handler.rs +++ b/src/domain/sql_backend_handler.rs @@ -117,7 +117,7 @@ impl BackendHandler for SqlBackendHandler { Ok(groups) } - async fn get_user_details(&self, request: UserDetailsRequest) -> Result { + async fn get_user_details(&self, user_id: &str) -> Result { let query = Query::select() .column(Users::UserId) .column(Users::Email) @@ -127,7 +127,7 @@ impl BackendHandler for SqlBackendHandler { .column(Users::Avatar) .column(Users::CreationDate) .from(Users::Table) - .and_where(Expr::col(Users::UserId).eq(request.user_id)) + .and_where(Expr::col(Users::UserId).eq(user_id)) .to_string(DbQueryBuilder {}); Ok(sqlx::query_as::<_, User>(&query) @@ -470,21 +470,11 @@ mod tests { let handler = SqlBackendHandler::new(config, sql_pool); insert_user(&handler, "bob", "bob00").await; { - let user = handler - .get_user_details(UserDetailsRequest { - user_id: String::from("bob"), - }) - .await - .unwrap(); + let user = handler.get_user_details("bob").await.unwrap(); assert_eq!(user.user_id, "bob".to_string()); } { - handler - .get_user_details(UserDetailsRequest { - user_id: String::from("John"), - }) - .await - .unwrap_err(); + handler.get_user_details("John").await.unwrap_err(); } } #[tokio::test] diff --git a/src/infra/graphql/mutation.rs b/src/infra/graphql/mutation.rs index 717c72e..fa8555b 100644 --- a/src/infra/graphql/mutation.rs +++ b/src/infra/graphql/mutation.rs @@ -1,6 +1,5 @@ use crate::domain::handler::BackendHandler; use juniper::{graphql_object, FieldResult, GraphQLInputObject}; -use lldap_model::UserDetailsRequest; use super::api::Context; @@ -49,7 +48,7 @@ impl Mutation { .await?; Ok(context .handler - .get_user_details(UserDetailsRequest { user_id: user.id }) + .get_user_details(&user.id) .await .map(Into::into)?) } diff --git a/src/infra/graphql/query.rs b/src/infra/graphql/query.rs index 6ca6e02..2d9d929 100644 --- a/src/infra/graphql/query.rs +++ b/src/infra/graphql/query.rs @@ -1,6 +1,5 @@ use crate::domain::handler::BackendHandler; use juniper::{graphql_object, FieldResult, GraphQLInputObject}; -use lldap_model::UserDetailsRequest; use serde::{Deserialize, Serialize}; use std::convert::TryInto; @@ -95,7 +94,7 @@ impl Query { } Ok(context .handler - .get_user_details(UserDetailsRequest { user_id }) + .get_user_details(&user_id) .await .map(Into::into)?) } @@ -242,9 +241,7 @@ mod tests { let mut mock = MockTestBackendHandler::new(); mock.expect_get_user_details() - .with(eq(UserDetailsRequest { - user_id: "bob".to_string(), - })) + .with(eq("bob")) .return_once(|_| { Ok(lldap_model::User { user_id: "bob".to_string(), diff --git a/src/infra/tcp_backend_handler.rs b/src/infra/tcp_backend_handler.rs index 823ccc4..010ab44 100644 --- a/src/infra/tcp_backend_handler.rs +++ b/src/infra/tcp_backend_handler.rs @@ -28,7 +28,7 @@ mockall::mock! { impl BackendHandler for TestTcpBackendHandler { async fn list_users(&self, filters: Option) -> DomainResult>; async fn list_groups(&self) -> DomainResult>; - async fn get_user_details(&self, request: UserDetailsRequest) -> DomainResult; + 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<()>;