Files
vrbattles-api/src/models/user.rs
VinceC cac4b83140 Add utoipa and Scalar for API documentation
- Add utoipa and utoipa-scalar dependencies
- Add ToSchema derives to all models
- Add OpenAPI path annotations to auth, users, and health handlers
- Create openapi.rs module with API documentation
- Serve Scalar UI at /docs endpoint
- Include JWT bearer auth security scheme

Co-Authored-By: Warp <agent@warp.dev>
2026-01-20 01:30:10 -06:00

95 lines
2.4 KiB
Rust

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use utoipa::ToSchema;
/// User model representing the users table
#[derive(Debug, Clone, Serialize, Deserialize, FromRow, ToSchema)]
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, ToSchema)]
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, ToSchema)]
pub struct CreateUser {
pub firstname: String,
pub lastname: String,
pub username: String,
pub email: String,
pub password: String,
}
/// Update user request
#[derive(Debug, Deserialize, ToSchema)]
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, ToSchema)]
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>,
}