Initial commit: VRBattles API
This commit is contained in:
71
src/models/team_player.rs
Normal file
71
src/models/team_player.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::FromRow;
|
||||
|
||||
/// Team player positions
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PlayerPosition {
|
||||
Captain,
|
||||
#[serde(rename = "co-captain")]
|
||||
CoCaptain,
|
||||
Member,
|
||||
}
|
||||
|
||||
impl PlayerPosition {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
PlayerPosition::Captain => "captain",
|
||||
PlayerPosition::CoCaptain => "co-captain",
|
||||
PlayerPosition::Member => "member",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_str(s: &str) -> Option<Self> {
|
||||
match s.to_lowercase().as_str() {
|
||||
"captain" => Some(PlayerPosition::Captain),
|
||||
"co-captain" => Some(PlayerPosition::CoCaptain),
|
||||
"member" => Some(PlayerPosition::Member),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Team player status
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub enum TeamPlayerStatus {
|
||||
Pending = 0,
|
||||
Active = 1,
|
||||
}
|
||||
|
||||
impl From<i32> for TeamPlayerStatus {
|
||||
fn from(val: i32) -> Self {
|
||||
match val {
|
||||
1 => TeamPlayerStatus::Active,
|
||||
_ => TeamPlayerStatus::Pending,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Team player model representing the team_players table
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
|
||||
pub struct TeamPlayer {
|
||||
pub id: i32,
|
||||
pub date_created: DateTime<Utc>,
|
||||
pub team_id: i32,
|
||||
pub player_id: i32,
|
||||
pub position: String,
|
||||
pub status: i32,
|
||||
}
|
||||
|
||||
/// Join team request
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct JoinTeamRequest {
|
||||
pub team_id: i32,
|
||||
}
|
||||
|
||||
/// Change position request
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChangePositionRequest {
|
||||
pub position: String,
|
||||
}
|
||||
Reference in New Issue
Block a user