From 9dd579e32ecfdaf5089ae817b551011a0580ac5e Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Tue, 31 Aug 2021 16:20:15 +0200 Subject: [PATCH] model: move User and Group definition to backend --- model/src/lib.rs | 31 ------------------------------- src/domain/handler.rs | 32 +++++++++++++++++++++++++++++++- src/infra/graphql/query.rs | 16 ++++++++-------- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/model/src/lib.rs b/model/src/lib.rs index 349d7a6..e29da83 100644 --- a/model/src/lib.rs +++ b/model/src/lib.rs @@ -67,37 +67,6 @@ pub mod registration { } } -#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(not(target_arch = "wasm32"), derive(sqlx::FromRow))] -pub struct User { - pub user_id: String, - pub email: String, - pub display_name: Option, - pub first_name: Option, - pub last_name: Option, - // pub avatar: ?, - pub creation_date: chrono::DateTime, -} - -impl Default for User { - fn default() -> Self { - User { - user_id: String::new(), - email: String::new(), - display_name: None, - first_name: None, - last_name: None, - creation_date: Utc.timestamp(0, 0), - } - } -} - -#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] -pub struct Group { - pub display_name: String, - pub users: Vec, -} - #[derive(Clone, Serialize, Deserialize)] pub struct JWTClaims { pub exp: DateTime, diff --git a/src/domain/handler.rs b/src/domain/handler.rs index 2aaf456..84bc640 100644 --- a/src/domain/handler.rs +++ b/src/domain/handler.rs @@ -3,7 +3,37 @@ use async_trait::async_trait; use serde::{Deserialize, Serialize}; use std::collections::HashSet; -pub use lldap_model::{Group, User}; +#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] +#[cfg_attr(not(target_arch = "wasm32"), derive(sqlx::FromRow))] +pub struct User { + pub user_id: String, + pub email: String, + pub display_name: Option, + pub first_name: Option, + pub last_name: Option, + // pub avatar: ?, + pub creation_date: chrono::DateTime, +} + +impl Default for User { + fn default() -> Self { + use chrono::TimeZone; + User { + user_id: String::new(), + email: String::new(), + display_name: None, + first_name: None, + last_name: None, + creation_date: chrono::Utc.timestamp(0, 0), + } + } +} + +#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] +pub struct Group { + pub display_name: String, + pub users: Vec, +} #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] pub struct BindRequest { diff --git a/src/infra/graphql/query.rs b/src/infra/graphql/query.rs index 2d9d929..4fca1f1 100644 --- a/src/infra/graphql/query.rs +++ b/src/infra/graphql/query.rs @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize}; use std::convert::TryInto; type DomainRequestFilter = crate::domain::handler::RequestFilter; +type DomainUser = crate::domain::handler::User; use super::api::Context; #[derive(PartialEq, Eq, Debug, GraphQLInputObject)] @@ -117,14 +118,14 @@ impl Query { #[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] /// Represents a single user. pub struct User { - user: lldap_model::User, + user: DomainUser, _phantom: std::marker::PhantomData>, } impl Default for User { fn default() -> Self { Self { - user: lldap_model::User::default(), + user: DomainUser::default(), _phantom: std::marker::PhantomData, } } @@ -166,8 +167,8 @@ impl User { } } -impl From for User { - fn from(user: lldap_model::User) -> Self { +impl From for User { + fn from(user: DomainUser) -> Self { Self { user, _phantom: std::marker::PhantomData, @@ -243,7 +244,7 @@ mod tests { mock.expect_get_user_details() .with(eq("bob")) .return_once(|_| { - Ok(lldap_model::User { + Ok(DomainUser { user_id: "bob".to_string(), email: "bob@bobbers.on".to_string(), ..Default::default() @@ -298,7 +299,6 @@ mod tests { let mut mock = MockTestBackendHandler::new(); use crate::domain::handler::RequestFilter; - use lldap_model::User; mock.expect_list_users() .with(eq(Some(RequestFilter::Or(vec![ RequestFilter::Equality("id".to_string(), "bob".to_string()), @@ -306,12 +306,12 @@ mod tests { ])))) .return_once(|_| { Ok(vec![ - User { + DomainUser { user_id: "bob".to_string(), email: "bob@bobbers.on".to_string(), ..Default::default() }, - User { + DomainUser { user_id: "robert".to_string(), email: "robert@bobbers.on".to_string(), ..Default::default()