user_dto.rs
61 lignes · 1784 octets
/// User DTOs for API requests and responses /// Feature 002: Database and Users use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use uuid::Uuid; use validator::Validate; /// Request body for creating a new user #[derive(Debug, Deserialize, Serialize, Clone, Validate)] pub struct CreateUserRequest { /// Username (3-64 characters) pub username: String, /// Email address pub email: String, /// Password (will be hashed, optional - generates default if not provided) pub password: Option<String>, /// Roles to assign to the user pub roles: Vec<String>, } /// Response for a single user #[derive(Debug, Serialize, Deserialize, Clone)] pub struct UserResponse { /// User ID pub id: Uuid, /// Username pub username: String, /// Email address pub email: String, /// Flag indicating if user must change password on next login pub must_change_password: bool, /// User roles pub roles: Vec<String>, /// Creation timestamp pub created_at: DateTime<Utc>, /// Last update timestamp pub updated_at: DateTime<Utc>, } impl From<rustwarden_core::models::user::Model> for UserResponse { fn from(user: rustwarden_core::models::user::Model) -> Self { Self { id: user.id, username: user.username, email: user.email, must_change_password: user.must_change_password, roles: vec![], // Roles need to be fetched separately created_at: user.created_at, updated_at: user.updated_at, } } } /// Response for list of users #[derive(Debug, Serialize, Deserialize)] pub struct UserListResponse { /// List of users pub users: Vec<UserResponse>, /// Total count pub total: usize, }
GitRust