Migrate datetimes to UTC

This commit is contained in:
Valentin Tolmer 2021-08-30 08:48:06 +02:00 committed by nitnelave
parent 848cc86d73
commit 0ecd9ed263
8 changed files with 16 additions and 15 deletions

1
app/src/graphql.rs Normal file
View File

@ -0,0 +1 @@
pub type DateTimeUtc = chrono::DateTime<chrono::Utc>;

View File

@ -4,6 +4,7 @@ mod api;
mod app; mod app;
mod cookies; mod cookies;
mod create_user; mod create_user;
mod graphql;
mod login; mod login;
mod logout; mod logout;
mod user_details; mod user_details;

View File

@ -10,7 +10,7 @@ use yew::services::{fetch::FetchTask, ConsoleService};
schema_path = "../schema.graphql", schema_path = "../schema.graphql",
query_path = "queries/list_users.graphql", query_path = "queries/list_users.graphql",
response_derives = "Debug", response_derives = "Debug",
custom_scalars_module = "chrono" custom_scalars_module = "crate::graphql"
)] )]
pub struct ListUsersQuery; pub struct ListUsersQuery;
@ -89,7 +89,7 @@ impl Component for UserTable {
<td>{&u.display_name.as_ref().unwrap_or(&String::new())}</td> <td>{&u.display_name.as_ref().unwrap_or(&String::new())}</td>
<td>{&u.first_name.as_ref().unwrap_or(&String::new())}</td> <td>{&u.first_name.as_ref().unwrap_or(&String::new())}</td>
<td>{&u.last_name.as_ref().unwrap_or(&String::new())}</td> <td>{&u.last_name.as_ref().unwrap_or(&String::new())}</td>
<td>{&u.creation_date}</td> <td>{&u.creation_date.with_timezone(&chrono::Local)}</td>
</tr> </tr>
} }
}) })

View File

@ -100,7 +100,7 @@ pub struct User {
pub first_name: Option<String>, pub first_name: Option<String>,
pub last_name: Option<String>, pub last_name: Option<String>,
// pub avatar: ?, // pub avatar: ?,
pub creation_date: chrono::NaiveDateTime, pub creation_date: chrono::DateTime<chrono::Utc>,
} }
impl Default for User { impl Default for User {
@ -111,7 +111,7 @@ impl Default for User {
display_name: None, display_name: None,
first_name: None, first_name: None,
last_name: None, last_name: None,
creation_date: chrono::NaiveDateTime::from_timestamp(0, 0), creation_date: Utc.timestamp(0, 0),
} }
} }
} }

View File

@ -20,22 +20,22 @@ input RequestFilter {
eq: EqualityConstraint eq: EqualityConstraint
} }
"DateTime"
scalar DateTimeUtc
type Query { type Query {
apiVersion: String! apiVersion: String!
user(userId: String!): User! user(userId: String!): User!
users(filters: RequestFilter): [User!]! users(filters: RequestFilter): [User!]!
} }
"NaiveDateTime"
scalar NaiveDateTime
type User { type User {
id: String! id: String!
email: String! email: String!
displayName: String displayName: String
firstName: String firstName: String
lastName: String lastName: String
creationDate: NaiveDateTime! creationDate: DateTimeUtc!
"The groups to which this user belongs." "The groups to which this user belongs."
groups: [Group!]! groups: [Group!]!
} }

View File

@ -120,7 +120,7 @@ pub async fn init_table(pool: &Pool) -> sqlx::Result<()> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use chrono::NaiveDateTime; use chrono::prelude::*;
use sqlx::{Column, Row}; use sqlx::{Column, Row};
#[actix_rt::test] #[actix_rt::test]
@ -138,8 +138,8 @@ mod tests {
assert_eq!(row.column(0).name(), "display_name"); assert_eq!(row.column(0).name(), "display_name");
assert_eq!(row.get::<String, _>("display_name"), "Bob Bobbersön"); assert_eq!(row.get::<String, _>("display_name"), "Bob Bobbersön");
assert_eq!( assert_eq!(
row.get::<NaiveDateTime, _>("creation_date"), row.get::<DateTime<Utc>, _>("creation_date"),
NaiveDateTime::from_timestamp(0, 0) Utc.timestamp(0, 0),
); );
} }

View File

@ -157,7 +157,7 @@ impl<Handler: BackendHandler + Sync> User<Handler> {
self.user.last_name.as_ref() self.user.last_name.as_ref()
} }
fn creation_date(&self) -> chrono::NaiveDateTime { fn creation_date(&self) -> chrono::DateTime<chrono::Utc> {
self.user.creation_date self.user.creation_date
} }

View File

@ -277,7 +277,6 @@ mod tests {
use super::*; use super::*;
use crate::domain::handler::BindRequest; use crate::domain::handler::BindRequest;
use crate::domain::handler::MockTestBackendHandler; use crate::domain::handler::MockTestBackendHandler;
use chrono::NaiveDateTime;
use mockall::predicate::eq; use mockall::predicate::eq;
use tokio; use tokio;
@ -487,7 +486,7 @@ mod tests {
display_name: Some("Bôb Böbberson".to_string()), display_name: Some("Bôb Böbberson".to_string()),
first_name: Some("Bôb".to_string()), first_name: Some("Bôb".to_string()),
last_name: Some("Böbberson".to_string()), last_name: Some("Böbberson".to_string()),
creation_date: NaiveDateTime::from_timestamp(1_000_000, 0), ..Default::default()
}, },
User { User {
user_id: "jim".to_string(), user_id: "jim".to_string(),
@ -495,7 +494,7 @@ mod tests {
display_name: Some("Jimminy Cricket".to_string()), display_name: Some("Jimminy Cricket".to_string()),
first_name: Some("Jim".to_string()), first_name: Some("Jim".to_string()),
last_name: Some("Cricket".to_string()), last_name: Some("Cricket".to_string()),
creation_date: NaiveDateTime::from_timestamp(1_500_000, 0), ..Default::default()
}, },
]) ])
}); });