//! User model and related types. use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use uuid::Uuid; /// User role enum matching the Postgres `user_role` CHECK constraint. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum UserRole { User, Admin, } impl UserRole { /// Convert from database string representation. pub fn from_db(s: &str) -> Self { match s { "admin" => UserRole::Admin, _ => UserRole::User, } } /// Convert to database string representation. pub fn as_str(&self) -> &'static str { match self { UserRole::User => "user", UserRole::Admin => "admin", } } } impl std::fmt::Display for UserRole { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.as_str()) } } /// A user record from the database. #[derive(Debug, Clone, Serialize)] pub struct User { pub id: Uuid, pub email: String, pub display_name: Option, pub role: UserRole, pub created_at: DateTime, pub updated_at: DateTime, } /// Response shape for `GET /api/v1/auth/me`. #[derive(Debug, Serialize)] pub struct MeResponse { pub id: Uuid, pub email: String, pub display_name: Option, pub role: String, pub created_at: DateTime, }