Initial commit: VRBattles API
This commit is contained in:
93
src/models/user.rs
Normal file
93
src/models/user.rs
Normal file
@@ -0,0 +1,93 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::FromRow;
|
||||
|
||||
/// User model representing the users table
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
|
||||
pub struct User {
|
||||
pub id: i32,
|
||||
pub date_registered: DateTime<Utc>,
|
||||
pub firstname: String,
|
||||
pub lastname: String,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
#[serde(skip_serializing)]
|
||||
pub password: String,
|
||||
pub is_admin: bool,
|
||||
pub profile: Option<String>,
|
||||
#[serde(skip_serializing)]
|
||||
pub password_reset_token: Option<String>,
|
||||
// OpenSkill rating fields
|
||||
pub mu: Option<f32>,
|
||||
pub sigma: Option<f32>,
|
||||
pub ordinal: Option<f32>,
|
||||
pub mmr: Option<f32>,
|
||||
}
|
||||
|
||||
/// User public profile (without sensitive data)
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct UserProfile {
|
||||
pub id: i32,
|
||||
pub date_registered: DateTime<Utc>,
|
||||
pub firstname: String,
|
||||
pub lastname: String,
|
||||
pub username: String,
|
||||
pub profile: Option<String>,
|
||||
pub mu: f64,
|
||||
pub sigma: f64,
|
||||
pub ordinal: f64,
|
||||
pub mmr: f64,
|
||||
}
|
||||
|
||||
impl From<User> for UserProfile {
|
||||
fn from(user: User) -> Self {
|
||||
Self {
|
||||
id: user.id,
|
||||
date_registered: user.date_registered,
|
||||
firstname: user.firstname,
|
||||
lastname: user.lastname,
|
||||
username: user.username,
|
||||
profile: user.profile,
|
||||
mu: user.mu.unwrap_or(25.0) as f64,
|
||||
sigma: user.sigma.unwrap_or(8.333333) as f64,
|
||||
ordinal: user.ordinal.unwrap_or(0.0) as f64,
|
||||
mmr: user.mmr.unwrap_or(1500.0) as f64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create user request (internal use)
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CreateUser {
|
||||
pub firstname: String,
|
||||
pub lastname: String,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
/// Update user request
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct UpdateUser {
|
||||
pub firstname: Option<String>,
|
||||
pub lastname: Option<String>,
|
||||
pub username: Option<String>,
|
||||
pub profile: Option<String>,
|
||||
}
|
||||
|
||||
/// Player stats response
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct PlayerStats {
|
||||
pub id: i32,
|
||||
pub username: String,
|
||||
pub firstname: String,
|
||||
pub lastname: String,
|
||||
pub profile: Option<String>,
|
||||
pub mu: f64,
|
||||
pub sigma: f64,
|
||||
pub ordinal: f64,
|
||||
pub mmr: f64,
|
||||
pub team_id: Option<i32>,
|
||||
pub team_name: Option<String>,
|
||||
pub position: Option<String>,
|
||||
}
|
||||
Reference in New Issue
Block a user