All domains and enums, and dtos
This commit is contained in:
parent
07caf843d4
commit
aa165dbcb4
|
@ -2,6 +2,306 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1"
|
||||
dependencies = [
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"time",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
|
||||
|
||||
[[package]]
|
||||
name = "dev-dtos"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/franklinblanco/user-dtos.git#3b3ffde695753edb4e7ffdf722299b372f2c0bd0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "err"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/franklinblanco/err.git#42237f4a4be71530933f920f7e5eb6dbf1d0c75e"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "league-types"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dev-dtos",
|
||||
"err",
|
||||
"rust_decimal",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7bd7356a8122b6c4a24a82b278680c73357984ca2fc79a0f9fa6dea7dced7c58"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust_decimal"
|
||||
version = "1.26.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee9164faf726e4f3ece4978b25ca877ddc6802fa77f38cdccb32c7f805ecd70c"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"num-traits",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.145"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.145"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
|
|
@ -8,7 +8,12 @@ license = "MIT"
|
|||
readme = "README.md"
|
||||
repository = "https://github.com/franklinblanco/league-types.git"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[lib]
|
||||
|
||||
[dependencies]
|
||||
err = { git = "https://github.com/franklinblanco/err.git" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
chrono = { version = "0.4", features = [ "serde" ] }
|
||||
rust_decimal = "1.26"
|
||||
|
||||
err = { git = "https://github.com/franklinblanco/err.git" }
|
||||
dev-dtos = { git = "https://github.com/franklinblanco/user-dtos.git" }
|
|
@ -0,0 +1,3 @@
|
|||
pub struct Count {
|
||||
pub count: i64,
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use err::Error;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum LeaguePlayerStatus {
|
||||
Denied,
|
||||
Joined,
|
||||
Requested,
|
||||
Kicked
|
||||
}
|
||||
impl Display for LeaguePlayerStatus {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
LeaguePlayerStatus::Denied => write!(f, "Denied"),
|
||||
LeaguePlayerStatus::Joined => write!(f, "Joined"),
|
||||
LeaguePlayerStatus::Requested => write!(f, "Requested"),
|
||||
LeaguePlayerStatus::Kicked => write!(f, "Kicked"),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl FromStr for LeaguePlayerStatus {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"Denied" => Ok(Self::Denied),
|
||||
"Joined" => Ok(Self::Joined),
|
||||
"Requested" => Ok(Self::Requested),
|
||||
"Kicked" => Ok(Self::Kicked),
|
||||
_ => Err(Error::Unspecified) //TODO: Create ParseStr error in actix_web_utils
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
pub mod order;
|
||||
pub mod league_player_status;
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
/// Enum to signal from the client how they want their data.
|
||||
/// Convention: "Name+Asc/Desc" Asc = Ascending order | Desc = Descending order.
|
||||
pub enum OrderBy{
|
||||
RelevanceAsc,
|
||||
AlphabeticalAsc,
|
||||
TimeCreatedAsc,
|
||||
|
||||
RelevanceDesc,
|
||||
AlphabeticalDesc,
|
||||
TimeCreatedDesc,
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
use chrono::{NaiveDateTime, Utc};
|
||||
use rust_decimal::Decimal;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Field {
|
||||
pub id: u32,
|
||||
pub place_id: u32,
|
||||
pub time_created: NaiveDateTime,
|
||||
pub last_updated: NaiveDateTime,
|
||||
pub country: String,
|
||||
pub city: String,
|
||||
pub name: String,
|
||||
pub price_per_hour: Decimal,
|
||||
pub currency: String,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
use err::Error;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use rust_decimal::Decimal;
|
||||
|
||||
|
||||
use crate::dto::league::LeagueForCreationDto;
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct League {
|
||||
pub id: u32,
|
||||
pub owner_id: u32,
|
||||
pub sport_id: u32,
|
||||
pub place_id: u32,
|
||||
pub time_created: NaiveDateTime,
|
||||
pub last_updated: NaiveDateTime,
|
||||
/// 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
|
||||
/// 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,
|
||||
/// This is a string because it's actually meaningless right now.
|
||||
/// We're not taking payments so this doesn't matter, it's just what the user wants.
|
||||
pub currency: Option<String>,
|
||||
pub max_players: u32,
|
||||
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 {
|
||||
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(),
|
||||
None => LeagueVisibility::Public.to_string(),
|
||||
},
|
||||
date_and_time: league_dto.date_and_time, cost_to_join: league_dto.cost_to_join, currency: league_dto.currency, max_players: league_dto.max_players, description: league_dto.description
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum LeagueState {
|
||||
/// Taking new players
|
||||
Open,
|
||||
/// No more people
|
||||
Closed
|
||||
}
|
||||
impl Display for LeagueState {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
LeagueState::Open => write!(f, "Open"),
|
||||
LeagueState::Closed => write!(f, "Closed"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum LeagueVisibility {
|
||||
/// Open to anyone, anyone can join
|
||||
Public,
|
||||
/// People request to join
|
||||
Private,
|
||||
/// Only owner can see
|
||||
Unlisted
|
||||
}
|
||||
|
||||
impl Display for LeagueVisibility {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
LeagueVisibility::Public => write!(f, "Public"),
|
||||
LeagueVisibility::Private => write!(f, "Private"),
|
||||
LeagueVisibility::Unlisted => write!(f, "Unlisted"),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl FromStr for LeagueVisibility {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"Public" => Ok(LeagueVisibility::Public),
|
||||
"Private" => Ok(LeagueVisibility::Private),
|
||||
"Unlisted" => Ok(LeagueVisibility::Unlisted),
|
||||
_ => Err(Error::Unspecified)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
use chrono::{NaiveDateTime, Utc};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::dto::league_player::JoinRequest;
|
||||
|
||||
use super::enums::league_player_status::LeaguePlayerStatus;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct LeaguePlayer {
|
||||
pub id: u32,
|
||||
pub league_id: u32,
|
||||
pub player_id: u32,
|
||||
pub time_created: NaiveDateTime,
|
||||
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() }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
pub mod field;
|
||||
pub mod league;
|
||||
pub mod place;
|
||||
pub mod player;
|
||||
pub mod sport_category;
|
||||
pub mod sport;
|
||||
pub mod enums;
|
||||
pub mod league_player;
|
||||
pub mod trust;
|
||||
pub mod dao_utils;
|
|
@ -0,0 +1,23 @@
|
|||
use chrono::{NaiveDateTime, Utc};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Place{
|
||||
pub id: u32,
|
||||
pub time_created: NaiveDateTime,
|
||||
pub last_updated: NaiveDateTime,
|
||||
pub name: String,
|
||||
pub sport_id: u32,
|
||||
pub country: String,
|
||||
pub state: Option<String>,
|
||||
pub city: String,
|
||||
pub address: String,
|
||||
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 }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
use chrono::{NaiveDateTime, Utc, NaiveDate};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::dto::player::PlayerForCreationDto;
|
||||
|
||||
//TODO: Remove sensitive information from player struct
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Player {
|
||||
pub id: u32,
|
||||
pub time_created: NaiveDateTime,
|
||||
pub last_updated: NaiveDateTime,
|
||||
pub name: String,
|
||||
pub birth_date: NaiveDate,
|
||||
pub country: String,
|
||||
pub city: String,
|
||||
pub identification_number: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
pub profile_picture_url: Option<String>,
|
||||
pub id_verified: bool,
|
||||
pub phone_number_verified: bool,
|
||||
}
|
||||
|
||||
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();
|
||||
self.id_verified = false;
|
||||
self.identification_number = None;
|
||||
self.last_updated = Utc::now().naive_utc();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
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 }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SportCategory {
|
||||
pub id: u32,
|
||||
pub name: String,
|
||||
}
|
||||
impl SportCategory {
|
||||
pub fn new() -> SportCategory {
|
||||
SportCategory { id: 0, name: "".to_string() }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
use chrono::{NaiveDateTime, Utc};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::dto::trust::TrustRequestDto;
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Trust {
|
||||
pub id: u32,
|
||||
/// The player who is trusting (sending the trust request)
|
||||
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
|
||||
}
|
||||
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 {
|
||||
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() }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
use chrono::NaiveDateTime;
|
||||
use serde::{Deserialize};
|
||||
use rust_decimal::Decimal;
|
||||
use crate::domain::league::LeagueVisibility;
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct LeagueForCreationDto{
|
||||
#[serde(rename = "userId")]
|
||||
pub user_id: u32,
|
||||
#[serde(rename = "authToken")]
|
||||
pub auth_token: String,
|
||||
#[serde(rename = "sportId")]
|
||||
pub sport_id: u32,
|
||||
#[serde(rename = "placeId")]
|
||||
pub place_id: u32,
|
||||
pub visibility: Option<LeagueVisibility>,
|
||||
#[serde(rename = "dateAndTime")]
|
||||
pub date_and_time: NaiveDateTime,
|
||||
#[serde(rename = "costToJoin")]
|
||||
pub cost_to_join: Decimal,
|
||||
pub currency: Option<String>,
|
||||
#[serde(rename = "maxPlayers")]
|
||||
pub max_players: u32,
|
||||
pub description: Option<String>
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct JoinRequest {
|
||||
#[serde(rename = "leagueId")]
|
||||
pub league_id: u32,
|
||||
#[serde(rename = "userId")]
|
||||
pub user_id: u32,
|
||||
#[serde(rename = "authToken")]
|
||||
pub auth_token: String,
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
pub mod player;
|
||||
pub mod league;
|
||||
pub mod league_player;
|
||||
pub mod trust;
|
|
@ -0,0 +1,59 @@
|
|||
use chrono::{NaiveDate};
|
||||
use dev_dtos::{dtos::user::user_dtos::UserForCreationDto, domain::user::credential_type::CredentialType};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::{domain::player::Player, APP_NAME};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PlayerForCreationDto {
|
||||
#[serde(rename = "phoneNumber")]
|
||||
pub phone_number: String,
|
||||
pub password: String,
|
||||
pub name: String,
|
||||
#[serde(rename = "birthDate")]
|
||||
pub birth_date: NaiveDate,
|
||||
pub country: String,
|
||||
pub city: String,
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PlayerForUpdateDto {
|
||||
pub name: Option<String>,
|
||||
#[serde(rename = "birthDate")]
|
||||
pub birth_date: Option<NaiveDate>,
|
||||
pub country: Option<String>,
|
||||
pub city: Option<String>,
|
||||
#[serde(rename = "identificationNumber")]
|
||||
pub identification_number: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
#[serde(rename = "profilePictureUrl")]
|
||||
pub profile_picture_url: Option<String>,
|
||||
#[serde(rename = "userId")]
|
||||
pub user_id: u32,
|
||||
#[serde(rename = "authToken")]
|
||||
pub auth_token: String,
|
||||
}
|
||||
|
||||
impl PlayerForCreationDto {
|
||||
pub fn convert_player_into_user_for_creation(player: &PlayerForCreationDto) -> UserForCreationDto{
|
||||
UserForCreationDto { app: APP_NAME.to_owned(), credential: player.phone_number.clone(), credential_type: CredentialType::PhoneNumber, password: player.password.clone(), name: player.name.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct PlayerProfileDto {
|
||||
pub name: String,
|
||||
pub country: String,
|
||||
pub bio: Option<String>,
|
||||
#[serde(rename = "profilePictureUrl")]
|
||||
pub profile_picture_url: Option<String>,
|
||||
#[serde(rename = "trustedPlayerCount")]
|
||||
pub trusted_player_count: i64,
|
||||
#[serde(rename = "trustedByPlayerCount")]
|
||||
pub trusted_by_player_count: i64,
|
||||
}
|
||||
|
||||
impl PlayerProfileDto {
|
||||
pub fn new_from_player_and_counts(player: &Player, trusted_player_count: i64, trusted_by_player_count: i64) -> PlayerProfileDto {
|
||||
PlayerProfileDto { name: player.name.clone(), country: player.country.clone(), bio: player.bio.clone(), profile_picture_url: player.profile_picture_url.clone(), trusted_player_count: trusted_player_count, trusted_by_player_count: trusted_by_player_count }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
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)]
|
||||
pub struct TrustRequestDto {
|
||||
#[serde(rename = "authToken")]
|
||||
pub auth_token: String,
|
||||
#[serde(rename = "trusterId")]
|
||||
pub truster_id: u32,
|
||||
#[serde(rename = "trusteeId")]
|
||||
pub trustee_id: u32,
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
pub mod domain;
|
||||
pub mod dto;
|
||||
|
||||
pub const APP_NAME: &str = "LEAGUE_APP";
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Loading…
Reference in New Issue