From 848cc86d738b72c56521ba85a4c440b38d918025 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Fri, 27 Aug 2021 01:10:45 +0200 Subject: [PATCH] api: add the rest of the fields to User --- app/queries/list_users.graphql | 7 ++++--- app/src/graphql_api.rs | 8 -------- app/src/lib.rs | 1 - app/src/user_table.rs | 35 ++++++++++++++++------------------ schema.graphql | 7 +++++++ src/infra/graphql/query.rs | 16 ++++++++++++++++ 6 files changed, 43 insertions(+), 31 deletions(-) delete mode 100644 app/src/graphql_api.rs diff --git a/app/queries/list_users.graphql b/app/queries/list_users.graphql index 4c2defb..211b8b0 100644 --- a/app/queries/list_users.graphql +++ b/app/queries/list_users.graphql @@ -2,8 +2,9 @@ query ListUsersQuery($filters: RequestFilter) { users(filters: $filters) { id email - groups { - id - } + displayName + firstName + lastName + creationDate } } diff --git a/app/src/graphql_api.rs b/app/src/graphql_api.rs deleted file mode 100644 index a32257d..0000000 --- a/app/src/graphql_api.rs +++ /dev/null @@ -1,8 +0,0 @@ -use graphql_client::GraphQLQuery; - -#[derive(GraphQLQuery)] -#[graphql( - schema_path = "../schema.graphql", - query_path = "queries/list_users.graphql" -)] -pub struct ListUsersQuery; diff --git a/app/src/lib.rs b/app/src/lib.rs index 82b54d3..b8fee89 100644 --- a/app/src/lib.rs +++ b/app/src/lib.rs @@ -4,7 +4,6 @@ mod api; mod app; mod cookies; mod create_user; -mod graphql_api; mod login; mod logout; mod user_details; diff --git a/app/src/user_table.rs b/app/src/user_table.rs index 330762d..6299059 100644 --- a/app/src/user_table.rs +++ b/app/src/user_table.rs @@ -1,19 +1,24 @@ -use crate::{ - api::HostService, - graphql_api::{ - list_users_query::{self, RequestFilter, ResponseData}, - ListUsersQuery, - }, -}; +use crate::api::HostService; use anyhow::{anyhow, Result}; -use lldap_model::*; +use graphql_client::GraphQLQuery; use yew::format::Json; use yew::prelude::*; use yew::services::{fetch::FetchTask, ConsoleService}; +#[derive(GraphQLQuery)] +#[graphql( + schema_path = "../schema.graphql", + query_path = "queries/list_users.graphql", + response_derives = "Debug", + custom_scalars_module = "chrono" +)] +pub struct ListUsersQuery; + +use list_users_query::{RequestFilter, ResponseData}; + pub struct UserTable { link: ComponentLink, - users: Option>>, + users: Option>>, // Used to keep the request alive long enough. _task: Option, } @@ -54,15 +59,7 @@ impl Component for UserTable { fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { Msg::ListUsersResponse(Ok(users)) => { - self.users = Some(Ok(users - .users - .into_iter() - .map(|u| User { - user_id: u.id, - email: u.email, - ..Default::default() - }) - .collect())); + self.users = Some(Ok(users.users.into_iter().collect())); ConsoleService::log(format!("Response: {:?}", Json(&self.users)).as_str()); true } @@ -87,7 +84,7 @@ impl Component for UserTable { .map(|u| { html! { - {&u.user_id} + {&u.id} {&u.email} {&u.display_name.as_ref().unwrap_or(&String::new())} {&u.first_name.as_ref().unwrap_or(&String::new())} diff --git a/schema.graphql b/schema.graphql index b3765a5..d8ff210 100644 --- a/schema.graphql +++ b/schema.graphql @@ -26,9 +26,16 @@ type Query { users(filters: RequestFilter): [User!]! } +"NaiveDateTime" +scalar NaiveDateTime + type User { id: String! email: String! + displayName: String + firstName: String + lastName: String + creationDate: NaiveDateTime! "The groups to which this user belongs." groups: [Group!]! } diff --git a/src/infra/graphql/query.rs b/src/infra/graphql/query.rs index 1565904..0fb55ea 100644 --- a/src/infra/graphql/query.rs +++ b/src/infra/graphql/query.rs @@ -145,6 +145,22 @@ impl User { &self.user.email } + fn display_name(&self) -> Option<&String> { + self.user.display_name.as_ref() + } + + fn first_name(&self) -> Option<&String> { + self.user.first_name.as_ref() + } + + fn last_name(&self) -> Option<&String> { + self.user.last_name.as_ref() + } + + fn creation_date(&self) -> chrono::NaiveDateTime { + self.user.creation_date + } + /// The groups to which this user belongs. async fn groups(&self, context: &Context) -> FieldResult>> { Ok(context