Implemented most traits and made some corrections
This commit is contained in:
parent
aa165dbcb4
commit
ac3dec3b18
@ -1,3 +1,6 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct Count {
|
||||
pub count: i64,
|
||||
}
|
@ -3,10 +3,11 @@ use std::{fmt::Display, str::FromStr};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use err::Error;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub enum LeaguePlayerStatus {
|
||||
Denied,
|
||||
Joined,
|
||||
#[default]
|
||||
Requested,
|
||||
Kicked
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use rust_decimal::Decimal;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct Field {
|
||||
pub id: u32,
|
||||
pub place_id: u32,
|
||||
|
@ -9,7 +9,7 @@ use rust_decimal::Decimal;
|
||||
use crate::dto::league::LeagueForCreationDto;
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct League {
|
||||
pub id: u32,
|
||||
pub owner_id: u32,
|
||||
@ -32,12 +32,9 @@ pub struct League {
|
||||
pub description: Option<String>
|
||||
}
|
||||
|
||||
impl League {
|
||||
pub fn new() -> League {
|
||||
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 }
|
||||
}
|
||||
pub fn new_from_league_for_creation_dto(league_dto: LeagueForCreationDto) -> League {
|
||||
League {
|
||||
impl From<LeagueForCreationDto> 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(),
|
||||
visibility: match league_dto.visibility {
|
||||
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 {
|
||||
/// Taking new players
|
||||
#[default]
|
||||
Open,
|
||||
/// No more people
|
||||
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 {
|
||||
/// Open to anyone, anyone can join
|
||||
#[default]
|
||||
Public,
|
||||
/// People request to join
|
||||
Private,
|
||||
|
@ -5,7 +5,7 @@ use crate::dto::league_player::JoinRequest;
|
||||
|
||||
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 id: u32,
|
||||
pub league_id: u32,
|
||||
@ -14,11 +14,8 @@ pub struct LeaguePlayer {
|
||||
pub last_updated: NaiveDateTime,
|
||||
pub status: String
|
||||
}
|
||||
impl LeaguePlayer {
|
||||
pub fn new_empty() -> LeaguePlayer {
|
||||
LeaguePlayer { id: 0, league_id: 0, player_id: 0, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc(), status: "".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() }
|
||||
impl From<JoinRequest> 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() }
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
use chrono::{NaiveDateTime};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct Place{
|
||||
pub id: u32,
|
||||
pub time_created: NaiveDateTime,
|
||||
@ -15,9 +15,4 @@ pub struct Place{
|
||||
pub maps_url: Option<String>,
|
||||
pub contact_number: 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 }
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ use serde::{Serialize, Deserialize};
|
||||
use crate::dto::player::PlayerForCreationDto;
|
||||
|
||||
//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 id: u32,
|
||||
pub time_created: NaiveDateTime,
|
||||
@ -20,13 +20,13 @@ pub struct Player {
|
||||
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{
|
||||
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 {
|
||||
self.birth_date = Utc::now().date_naive();
|
||||
self.city = "".to_string();
|
||||
|
@ -1,13 +1,8 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct Sport{
|
||||
pub id: u32,
|
||||
pub name: String,
|
||||
pub category_id: u32
|
||||
}
|
||||
impl Sport{
|
||||
pub fn new() -> Sport{
|
||||
Sport { id: 0, name: "".to_string(), category_id: 0 }
|
||||
}
|
||||
}
|
@ -1,12 +1,7 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct SportCategory {
|
||||
pub id: u32,
|
||||
pub name: String,
|
||||
}
|
||||
impl SportCategory {
|
||||
pub fn new() -> SportCategory {
|
||||
SportCategory { id: 0, name: "".to_string() }
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ use serde::{Serialize, Deserialize};
|
||||
use crate::dto::trust::TrustRequestDto;
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct Trust {
|
||||
pub id: u32,
|
||||
/// The player who is trusting (sending the trust request)
|
||||
@ -14,11 +14,9 @@ pub struct Trust {
|
||||
pub time_created: NaiveDateTime,
|
||||
pub last_updated: NaiveDateTime
|
||||
}
|
||||
impl Trust {
|
||||
pub fn new_empty() -> Trust {
|
||||
Trust { id: 0, truster_id: 0, trustee_id: 0, time_created: Utc::now().naive_utc(), last_updated: Utc::now().naive_utc() }
|
||||
}
|
||||
pub fn new_from_join_request(trust_dto: &TrustRequestDto) -> Trust {
|
||||
|
||||
impl From<TrustRequestDto> 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() }
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
use chrono::NaiveDateTime;
|
||||
use serde::{Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use rust_decimal::Decimal;
|
||||
use crate::domain::league::LeagueVisibility;
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct LeagueForCreationDto{
|
||||
#[serde(rename = "userId")]
|
||||
pub user_id: u32,
|
||||
|
@ -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 {
|
||||
#[serde(rename = "leagueId")]
|
||||
pub league_id: u32,
|
||||
|
@ -4,7 +4,7 @@ use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::{domain::player::Player, APP_NAME};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct PlayerForCreationDto {
|
||||
#[serde(rename = "phoneNumber")]
|
||||
pub phone_number: String,
|
||||
@ -15,7 +15,7 @@ pub struct PlayerForCreationDto {
|
||||
pub country: String,
|
||||
pub city: String,
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct PlayerForUpdateDto {
|
||||
pub name: Option<String>,
|
||||
#[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 name: String,
|
||||
pub country: String,
|
||||
|
@ -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
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct TrustRequestDto {
|
||||
#[serde(rename = "authToken")]
|
||||
pub auth_token: String,
|
||||
|
Loading…
Reference in New Issue
Block a user