model: inline the UserDetailsRequest

This commit is contained in:
Valentin Tolmer 2021-08-31 15:48:45 +02:00 committed by nitnelave
parent 6efafa99c8
commit 0dd05e5771
6 changed files with 10 additions and 30 deletions

View File

@ -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 {

View File

@ -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<RequestFilter>) -> Result<Vec<User>>;
async fn list_groups(&self) -> Result<Vec<Group>>;
async fn get_user_details(&self, request: UserDetailsRequest) -> Result<User>;
async fn get_user_details(&self, user_id: &str) -> Result<User>;
async fn create_user(&self, request: CreateUserRequest) -> Result<()>;
async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>;
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;
@ -49,7 +48,7 @@ mockall::mock! {
impl BackendHandler for TestBackendHandler {
async fn list_users(&self, filters: Option<RequestFilter>) -> Result<Vec<User>>;
async fn list_groups(&self) -> Result<Vec<Group>>;
async fn get_user_details(&self, request: UserDetailsRequest) -> Result<User>;
async fn get_user_details(&self, user_id: &str) -> Result<User>;
async fn create_user(&self, request: CreateUserRequest) -> Result<()>;
async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>;
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;

View File

@ -117,7 +117,7 @@ impl BackendHandler for SqlBackendHandler {
Ok(groups)
}
async fn get_user_details(&self, request: UserDetailsRequest) -> Result<User> {
async fn get_user_details(&self, user_id: &str) -> Result<User> {
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]

View File

@ -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<Handler: BackendHandler + Sync> Mutation<Handler> {
.await?;
Ok(context
.handler
.get_user_details(UserDetailsRequest { user_id: user.id })
.get_user_details(&user.id)
.await
.map(Into::into)?)
}

View File

@ -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<Handler: BackendHandler + Sync> Query<Handler> {
}
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(),

View File

@ -28,7 +28,7 @@ mockall::mock! {
impl BackendHandler for TestTcpBackendHandler {
async fn list_users(&self, filters: Option<RequestFilter>) -> DomainResult<Vec<User>>;
async fn list_groups(&self) -> DomainResult<Vec<Group>>;
async fn get_user_details(&self, request: UserDetailsRequest) -> DomainResult<User>;
async fn get_user_details(&self, user_id: &str) -> DomainResult<User>;
async fn get_user_groups(&self, user: &str) -> DomainResult<HashSet<String>>;
async fn create_user(&self, request: CreateUserRequest) -> DomainResult<()>;
async fn delete_user(&self, request: DeleteUserRequest) -> DomainResult<()>;