From 8aa1dd61d67b2fddd300e013a5a8fe0cc7029db8 Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 12 Oct 2022 15:04:42 -0400 Subject: [PATCH] Changed all NaiveDateTimes to DateTime --- src/domain/field.rs | 8 ++++---- src/domain/league.rs | 10 +++++----- src/domain/league_player.rs | 8 ++++---- src/domain/place.rs | 6 +++--- src/domain/player.rs | 10 +++++----- src/domain/trust.rs | 8 ++++---- src/dto/league.rs | 4 ++-- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/domain/field.rs b/src/domain/field.rs index 9fcaf8e..1d832a3 100644 --- a/src/domain/field.rs +++ b/src/domain/field.rs @@ -1,4 +1,4 @@ -use chrono::{NaiveDateTime, Utc}; +use chrono::{Utc, DateTime}; use rust_decimal::Decimal; use serde::{Serialize, Deserialize}; @@ -7,8 +7,8 @@ use serde::{Serialize, Deserialize}; pub struct Field { pub id: u32, pub place_id: u32, - pub time_created: NaiveDateTime, - pub last_updated: NaiveDateTime, + pub time_created: DateTime, + pub last_updated: DateTime, pub country: String, pub city: String, pub name: String, @@ -19,6 +19,6 @@ pub struct Field { impl Field { pub fn new() -> Field { - Field { id: 0, place_id: 0, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc(), country: "".to_string(), city: "".to_string(), name: "".to_string(), price_per_hour: Decimal::new(0, 0), currency: "".to_string(), description: None } + Field { id: 0, place_id: 0, time_created: Utc::now(), last_updated: Utc::now(), country: "".to_string(), city: "".to_string(), name: "".to_string(), price_per_hour: Decimal::new(0, 0), currency: "".to_string(), description: None } } } \ No newline at end of file diff --git a/src/domain/league.rs b/src/domain/league.rs index efddfd5..263b961 100644 --- a/src/domain/league.rs +++ b/src/domain/league.rs @@ -1,6 +1,6 @@ use std::{fmt::Display, str::FromStr}; -use chrono::{NaiveDateTime, Utc}; +use chrono::{Utc, DateTime}; use err::Error; use serde::{Serialize, Deserialize}; use rust_decimal::Decimal; @@ -15,13 +15,13 @@ pub struct League { pub owner_id: u32, pub sport_id: u32, pub place_id: u32, - pub time_created: NaiveDateTime, - pub last_updated: NaiveDateTime, + pub time_created: DateTime, + pub last_updated: DateTime, /// State as in: Is the league open or closed? Not the geographical sense. pub state: String, pub visibility: String, /// When is the league happening? - pub date_and_time: NaiveDateTime, //TODO: Switch from NaiveDateTime to TimeZones + pub date_and_time: DateTime, //TODO: Switch from DateTime to TimeZones /// This will be stored as a Decimal in the database but the actual input from the user /// will not be in rust_decimal::Decimal type. pub cost_to_join: Decimal, @@ -35,7 +35,7 @@ pub struct League { impl From for League { fn from(league_dto: LeagueForCreationDto) -> Self { Self { - id: 0, owner_id: league_dto.user_id, sport_id: league_dto.sport_id, place_id:league_dto.place_id, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc(), state: LeagueState::Open.to_string(), + id: 0, owner_id: league_dto.user_id, sport_id: league_dto.sport_id, place_id:league_dto.place_id, time_created: Utc::now(), last_updated: Utc::now(), state: LeagueState::Open.to_string(), visibility: match league_dto.visibility { Some(visibility) => visibility.to_string(), None => LeagueVisibility::Public.to_string(), diff --git a/src/domain/league_player.rs b/src/domain/league_player.rs index 5c98fd2..dd67db8 100644 --- a/src/domain/league_player.rs +++ b/src/domain/league_player.rs @@ -1,4 +1,4 @@ -use chrono::{NaiveDateTime, Utc}; +use chrono::{Utc, DateTime}; use serde::{Serialize, Deserialize}; use crate::dto::league_player::JoinRequest; @@ -10,12 +10,12 @@ pub struct LeaguePlayer { pub id: u32, pub league_id: u32, pub player_id: u32, - pub time_created: NaiveDateTime, - pub last_updated: NaiveDateTime, + pub time_created: DateTime, + pub last_updated: DateTime, pub status: String } impl From for LeaguePlayer { fn from(join_req: JoinRequest) -> Self { - Self { id: 0, league_id: join_req.league_id, player_id: join_req.user_id, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc(), status: LeaguePlayerStatus::Requested.to_string() } + Self { id: 0, league_id: join_req.league_id, player_id: join_req.user_id, time_created: Utc::now(), last_updated: Utc::now(), status: LeaguePlayerStatus::Requested.to_string() } } } \ No newline at end of file diff --git a/src/domain/place.rs b/src/domain/place.rs index 4eeed3f..1c94f59 100644 --- a/src/domain/place.rs +++ b/src/domain/place.rs @@ -1,11 +1,11 @@ -use chrono::{NaiveDateTime}; +use chrono::{Utc, DateTime}; use serde::{Serialize, Deserialize}; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)] pub struct Place{ pub id: u32, - pub time_created: NaiveDateTime, - pub last_updated: NaiveDateTime, + pub time_created: DateTime, + pub last_updated: DateTime, pub name: String, pub sport_id: u32, pub country: String, diff --git a/src/domain/player.rs b/src/domain/player.rs index f9ea495..ccb921c 100644 --- a/src/domain/player.rs +++ b/src/domain/player.rs @@ -1,4 +1,4 @@ -use chrono::{NaiveDateTime, Utc, NaiveDate}; +use chrono::{Utc, DateTime, NaiveDate}; use serde::{Serialize, Deserialize}; use crate::dto::player::PlayerForCreationDto; @@ -7,8 +7,8 @@ use crate::dto::player::PlayerForCreationDto; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)] pub struct Player { pub id: u32, - pub time_created: NaiveDateTime, - pub last_updated: NaiveDateTime, + pub time_created: DateTime, + pub last_updated: DateTime, pub name: String, pub birth_date: NaiveDate, pub country: String, @@ -22,7 +22,7 @@ pub struct Player { impl From for Player { fn from(player_dto: PlayerForCreationDto) -> Self { - Player { id: Default::default(), time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc(), name: player_dto.name.clone(), birth_date: player_dto.birth_date.clone(), country: player_dto.country.clone(), city: player_dto.city.clone(), identification_number: None, bio: None, profile_picture_url: None, id_verified: false, phone_number_verified: false } + Player { id: Default::default(), time_created: Utc::now(), last_updated: Utc::now().with_timezone(&Utc), name: player_dto.name.clone(), birth_date: player_dto.birth_date.clone(), country: player_dto.country.clone(), city: player_dto.city.clone(), identification_number: None, bio: None, profile_picture_url: None, id_verified: false, phone_number_verified: false } } } @@ -32,7 +32,7 @@ impl Player{ self.city = "".to_string(); self.id_verified = false; self.identification_number = None; - self.last_updated = Utc::now().naive_utc(); + self.last_updated = Utc::now(); self } } \ No newline at end of file diff --git a/src/domain/trust.rs b/src/domain/trust.rs index 61d8c7c..ab9c262 100644 --- a/src/domain/trust.rs +++ b/src/domain/trust.rs @@ -1,4 +1,4 @@ -use chrono::{NaiveDateTime, Utc}; +use chrono::{Utc, DateTime}; use serde::{Serialize, Deserialize}; use crate::dto::trust::TrustRequestDto; @@ -11,12 +11,12 @@ pub struct Trust { pub truster_id: u32, /// The player who is being trusted (recieving the trust request) pub trustee_id: u32, - pub time_created: NaiveDateTime, - pub last_updated: NaiveDateTime + pub time_created: DateTime, + pub last_updated: DateTime } impl From for Trust { fn from(trust_dto: TrustRequestDto) -> Self { - Trust { id: 0, truster_id: trust_dto.truster_id, trustee_id: trust_dto.trustee_id, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc() } + Trust { id: 0, truster_id: trust_dto.truster_id, trustee_id: trust_dto.trustee_id, time_created: Utc::now(), last_updated: Utc::now() } } } \ No newline at end of file diff --git a/src/dto/league.rs b/src/dto/league.rs index 65e8ed6..8f9148f 100644 --- a/src/dto/league.rs +++ b/src/dto/league.rs @@ -1,4 +1,4 @@ -use chrono::NaiveDateTime; +use chrono::{Utc, DateTime}; use serde::{Deserialize, Serialize}; use rust_decimal::Decimal; use crate::domain::league::LeagueVisibility; @@ -15,7 +15,7 @@ pub struct LeagueForCreationDto{ pub place_id: u32, pub visibility: Option, #[serde(rename = "dateAndTime")] - pub date_and_time: NaiveDateTime, + pub date_and_time: DateTime, #[serde(rename = "costToJoin")] pub cost_to_join: Decimal, pub currency: Option,