diff --git a/app/src/graphql.rs b/app/src/graphql.rs new file mode 100644 index 0000000..5556110 --- /dev/null +++ b/app/src/graphql.rs @@ -0,0 +1 @@ +pub type DateTimeUtc = chrono::DateTime; diff --git a/app/src/lib.rs b/app/src/lib.rs index b8fee89..6fa442f 100644 --- a/app/src/lib.rs +++ b/app/src/lib.rs @@ -4,6 +4,7 @@ mod api; mod app; mod cookies; mod create_user; +mod graphql; mod login; mod logout; mod user_details; diff --git a/app/src/user_table.rs b/app/src/user_table.rs index 6299059..c1b9207 100644 --- a/app/src/user_table.rs +++ b/app/src/user_table.rs @@ -10,7 +10,7 @@ use yew::services::{fetch::FetchTask, ConsoleService}; schema_path = "../schema.graphql", query_path = "queries/list_users.graphql", response_derives = "Debug", - custom_scalars_module = "chrono" + custom_scalars_module = "crate::graphql" )] pub struct ListUsersQuery; @@ -89,7 +89,7 @@ impl Component for UserTable { {&u.display_name.as_ref().unwrap_or(&String::new())} {&u.first_name.as_ref().unwrap_or(&String::new())} {&u.last_name.as_ref().unwrap_or(&String::new())} - {&u.creation_date} + {&u.creation_date.with_timezone(&chrono::Local)} } }) diff --git a/model/src/lib.rs b/model/src/lib.rs index 89a1a9a..fe1b067 100644 --- a/model/src/lib.rs +++ b/model/src/lib.rs @@ -100,7 +100,7 @@ pub struct User { pub first_name: Option, pub last_name: Option, // pub avatar: ?, - pub creation_date: chrono::NaiveDateTime, + pub creation_date: chrono::DateTime, } impl Default for User { @@ -111,7 +111,7 @@ impl Default for User { display_name: None, first_name: None, last_name: None, - creation_date: chrono::NaiveDateTime::from_timestamp(0, 0), + creation_date: Utc.timestamp(0, 0), } } } diff --git a/schema.graphql b/schema.graphql index d8ff210..eea8f9f 100644 --- a/schema.graphql +++ b/schema.graphql @@ -20,22 +20,22 @@ input RequestFilter { eq: EqualityConstraint } +"DateTime" +scalar DateTimeUtc + type Query { apiVersion: String! user(userId: String!): User! users(filters: RequestFilter): [User!]! } -"NaiveDateTime" -scalar NaiveDateTime - type User { id: String! email: String! displayName: String firstName: String lastName: String - creationDate: NaiveDateTime! + creationDate: DateTimeUtc! "The groups to which this user belongs." groups: [Group!]! } diff --git a/src/domain/sql_tables.rs b/src/domain/sql_tables.rs index 70b3dd8..6e17938 100644 --- a/src/domain/sql_tables.rs +++ b/src/domain/sql_tables.rs @@ -120,7 +120,7 @@ pub async fn init_table(pool: &Pool) -> sqlx::Result<()> { #[cfg(test)] mod tests { use super::*; - use chrono::NaiveDateTime; + use chrono::prelude::*; use sqlx::{Column, Row}; #[actix_rt::test] @@ -138,8 +138,8 @@ mod tests { assert_eq!(row.column(0).name(), "display_name"); assert_eq!(row.get::("display_name"), "Bob Bobbersön"); assert_eq!( - row.get::("creation_date"), - NaiveDateTime::from_timestamp(0, 0) + row.get::, _>("creation_date"), + Utc.timestamp(0, 0), ); } diff --git a/src/infra/graphql/query.rs b/src/infra/graphql/query.rs index 0fb55ea..5ea5c78 100644 --- a/src/infra/graphql/query.rs +++ b/src/infra/graphql/query.rs @@ -157,7 +157,7 @@ impl User { self.user.last_name.as_ref() } - fn creation_date(&self) -> chrono::NaiveDateTime { + fn creation_date(&self) -> chrono::DateTime { self.user.creation_date } diff --git a/src/infra/ldap_handler.rs b/src/infra/ldap_handler.rs index 438dfdf..4cebc8e 100644 --- a/src/infra/ldap_handler.rs +++ b/src/infra/ldap_handler.rs @@ -277,7 +277,6 @@ mod tests { use super::*; use crate::domain::handler::BindRequest; use crate::domain::handler::MockTestBackendHandler; - use chrono::NaiveDateTime; use mockall::predicate::eq; use tokio; @@ -487,7 +486,7 @@ mod tests { display_name: Some("Bôb Böbberson".to_string()), first_name: Some("Bôb".to_string()), last_name: Some("Böbberson".to_string()), - creation_date: NaiveDateTime::from_timestamp(1_000_000, 0), + ..Default::default() }, User { user_id: "jim".to_string(), @@ -495,7 +494,7 @@ mod tests { display_name: Some("Jimminy Cricket".to_string()), first_name: Some("Jim".to_string()), last_name: Some("Cricket".to_string()), - creation_date: NaiveDateTime::from_timestamp(1_500_000, 0), + ..Default::default() }, ]) });