Initial commit: VRBattles API

This commit is contained in:
root
2026-01-20 05:41:25 +00:00
commit c26a1820d5
42 changed files with 6187 additions and 0 deletions

71
src/models/team_player.rs Normal file
View 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,
}