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 cookies;
mod create_user;
mod graphql;
mod login;
mod logout;
mod user_details;

View File

@ -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 {
<td>{&u.display_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.creation_date}</td>
<td>{&u.creation_date.with_timezone(&chrono::Local)}</td>
</tr>
}
})

View File

@ -100,7 +100,7 @@ pub struct User {
pub first_name: Option<String>,
pub last_name: Option<String>,
// pub avatar: ?,
pub creation_date: chrono::NaiveDateTime,
pub creation_date: chrono::DateTime<chrono::Utc>,
}
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),
}
}
}

View File

@ -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!]!
}

View File

@ -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::<String, _>("display_name"), "Bob Bobbersön");
assert_eq!(
row.get::<NaiveDateTime, _>("creation_date"),
NaiveDateTime::from_timestamp(0, 0)
row.get::<DateTime<Utc>, _>("creation_date"),
Utc.timestamp(0, 0),
);
}

View File

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

View File

@ -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()
},
])
});