Implemented most traits and made some corrections

This commit is contained in:
Franklin 2022-10-08 18:09:12 -04:00
parent aa165dbcb4
commit ac3dec3b18
14 changed files with 40 additions and 57 deletions

View File

@ -1,3 +1,6 @@
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct Count { pub struct Count {
pub count: i64, pub count: i64,
} }

View File

@ -3,10 +3,11 @@ use std::{fmt::Display, str::FromStr};
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use err::Error; use err::Error;
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum LeaguePlayerStatus { pub enum LeaguePlayerStatus {
Denied, Denied,
Joined, Joined,
#[default]
Requested, Requested,
Kicked Kicked
} }

View File

@ -3,7 +3,7 @@ use rust_decimal::Decimal;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct Field { pub struct Field {
pub id: u32, pub id: u32,
pub place_id: u32, pub place_id: u32,

View File

@ -9,7 +9,7 @@ use rust_decimal::Decimal;
use crate::dto::league::LeagueForCreationDto; use crate::dto::league::LeagueForCreationDto;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct League { pub struct League {
pub id: u32, pub id: u32,
pub owner_id: u32, pub owner_id: u32,
@ -32,12 +32,9 @@ pub struct League {
pub description: Option<String> pub description: Option<String>
} }
impl League { impl From<LeagueForCreationDto> for League {
pub fn new() -> League { fn from(league_dto: LeagueForCreationDto) -> Self {
League { id: 0, owner_id: 0, sport_id: 0, place_id: 0, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc(), state: "".to_string(), visibility: "".to_string(), date_and_time: Utc::now().naive_utc(), cost_to_join: Decimal::new(0, 0), currency: None, max_players: 0, description: None } Self {
}
pub fn new_from_league_for_creation_dto(league_dto: LeagueForCreationDto) -> League {
League {
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().naive_utc(), last_updated: Utc::now().naive_utc(), state: LeagueState::Open.to_string(),
visibility: match league_dto.visibility { visibility: match league_dto.visibility {
Some(visibility) => visibility.to_string(), Some(visibility) => visibility.to_string(),
@ -48,9 +45,10 @@ impl League {
} }
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum LeagueState { pub enum LeagueState {
/// Taking new players /// Taking new players
#[default]
Open, Open,
/// No more people /// No more people
Closed Closed
@ -64,9 +62,10 @@ impl Display for LeagueState {
} }
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum LeagueVisibility { pub enum LeagueVisibility {
/// Open to anyone, anyone can join /// Open to anyone, anyone can join
#[default]
Public, Public,
/// People request to join /// People request to join
Private, Private,

View File

@ -5,7 +5,7 @@ use crate::dto::league_player::JoinRequest;
use super::enums::league_player_status::LeaguePlayerStatus; use super::enums::league_player_status::LeaguePlayerStatus;
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct LeaguePlayer { pub struct LeaguePlayer {
pub id: u32, pub id: u32,
pub league_id: u32, pub league_id: u32,
@ -14,11 +14,8 @@ pub struct LeaguePlayer {
pub last_updated: NaiveDateTime, pub last_updated: NaiveDateTime,
pub status: String pub status: String
} }
impl LeaguePlayer { impl From<JoinRequest> for LeaguePlayer {
pub fn new_empty() -> LeaguePlayer { fn from(join_req: JoinRequest) -> Self {
LeaguePlayer { id: 0, league_id: 0, player_id: 0, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc(), status: "".to_string()} 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() }
}
pub fn new_from_join_request(join_req: JoinRequest) -> LeaguePlayer {
LeaguePlayer { 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() }
} }
} }

View File

@ -1,7 +1,7 @@
use chrono::{NaiveDateTime, Utc}; use chrono::{NaiveDateTime};
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct Place{ pub struct Place{
pub id: u32, pub id: u32,
pub time_created: NaiveDateTime, pub time_created: NaiveDateTime,
@ -15,9 +15,4 @@ pub struct Place{
pub maps_url: Option<String>, pub maps_url: Option<String>,
pub contact_number: Option<String>, pub contact_number: Option<String>,
pub picture_url: Option<String> pub picture_url: Option<String>
}
impl Place {
pub fn new() -> Place{
Place { id: 0, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc(), name: "".to_string(), sport_id: 0, country: "".to_string(), state: None, city: "".to_string(), address: "".to_string(), maps_url: None, contact_number: None, picture_url: None }
}
} }

View File

@ -4,7 +4,7 @@ use serde::{Serialize, Deserialize};
use crate::dto::player::PlayerForCreationDto; use crate::dto::player::PlayerForCreationDto;
//TODO: Remove sensitive information from player struct //TODO: Remove sensitive information from player struct
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct Player { pub struct Player {
pub id: u32, pub id: u32,
pub time_created: NaiveDateTime, pub time_created: NaiveDateTime,
@ -20,13 +20,13 @@ pub struct Player {
pub phone_number_verified: bool, pub phone_number_verified: bool,
} }
impl From<PlayerForCreationDto> 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 }
}
}
impl Player{ impl Player{
pub fn new() -> Player {
Player { id: 0, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc(), name: "".to_string(), birth_date: Utc::now().date_naive(), country: "".to_string(), city: "".to_string(), identification_number: None, bio: None, profile_picture_url: None, id_verified: false, phone_number_verified: false }
}
pub fn new_from_creation_dto(player_dto: &PlayerForCreationDto, id: &u32) -> Player {
Player { id: *id, 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 }
}
pub fn clear_all_sensitive_fields(mut self) -> Self { pub fn clear_all_sensitive_fields(mut self) -> Self {
self.birth_date = Utc::now().date_naive(); self.birth_date = Utc::now().date_naive();
self.city = "".to_string(); self.city = "".to_string();

View File

@ -1,13 +1,8 @@
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct Sport{ pub struct Sport{
pub id: u32, pub id: u32,
pub name: String, pub name: String,
pub category_id: u32 pub category_id: u32
}
impl Sport{
pub fn new() -> Sport{
Sport { id: 0, name: "".to_string(), category_id: 0 }
}
} }

View File

@ -1,12 +1,7 @@
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct SportCategory { pub struct SportCategory {
pub id: u32, pub id: u32,
pub name: String, pub name: String,
}
impl SportCategory {
pub fn new() -> SportCategory {
SportCategory { id: 0, name: "".to_string() }
}
} }

View File

@ -4,7 +4,7 @@ use serde::{Serialize, Deserialize};
use crate::dto::trust::TrustRequestDto; use crate::dto::trust::TrustRequestDto;
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct Trust { pub struct Trust {
pub id: u32, pub id: u32,
/// The player who is trusting (sending the trust request) /// The player who is trusting (sending the trust request)
@ -14,11 +14,9 @@ pub struct Trust {
pub time_created: NaiveDateTime, pub time_created: NaiveDateTime,
pub last_updated: NaiveDateTime pub last_updated: NaiveDateTime
} }
impl Trust {
pub fn new_empty() -> Trust { impl From<TrustRequestDto> for Trust {
Trust { id: 0, truster_id: 0, trustee_id: 0, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc() } fn from(trust_dto: TrustRequestDto) -> Self {
}
pub fn new_from_join_request(trust_dto: &TrustRequestDto) -> Trust {
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().naive_utc(), last_updated: Utc::now().naive_utc() }
} }
} }

View File

@ -1,9 +1,9 @@
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use serde::{Deserialize}; use serde::{Deserialize, Serialize};
use rust_decimal::Decimal; use rust_decimal::Decimal;
use crate::domain::league::LeagueVisibility; use crate::domain::league::LeagueVisibility;
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct LeagueForCreationDto{ pub struct LeagueForCreationDto{
#[serde(rename = "userId")] #[serde(rename = "userId")]
pub user_id: u32, pub user_id: u32,

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct JoinRequest { pub struct JoinRequest {
#[serde(rename = "leagueId")] #[serde(rename = "leagueId")]
pub league_id: u32, pub league_id: u32,

View File

@ -4,7 +4,7 @@ use serde::{Serialize, Deserialize};
use crate::{domain::player::Player, APP_NAME}; use crate::{domain::player::Player, APP_NAME};
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct PlayerForCreationDto { pub struct PlayerForCreationDto {
#[serde(rename = "phoneNumber")] #[serde(rename = "phoneNumber")]
pub phone_number: String, pub phone_number: String,
@ -15,7 +15,7 @@ pub struct PlayerForCreationDto {
pub country: String, pub country: String,
pub city: String, pub city: String,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct PlayerForUpdateDto { pub struct PlayerForUpdateDto {
pub name: Option<String>, pub name: Option<String>,
#[serde(rename = "birthDate")] #[serde(rename = "birthDate")]
@ -39,7 +39,7 @@ impl PlayerForCreationDto {
} }
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct PlayerProfileDto { pub struct PlayerProfileDto {
pub name: String, pub name: String,
pub country: String, pub country: String,

View File

@ -2,7 +2,7 @@ use serde::{Serialize, Deserialize};
/// This DTO can be used to add to trusted list or to remove. Depends on the endpoint /// This DTO can be used to add to trusted list or to remove. Depends on the endpoint
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct TrustRequestDto { pub struct TrustRequestDto {
#[serde(rename = "authToken")] #[serde(rename = "authToken")]
pub auth_token: String, pub auth_token: String,