use crate::auth::jwt::types::TokenPair;
use crate::core::models::user::types::User;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize)]
pub struct RegisterRequest {
pub username: String,
pub email: String,
pub password: String,
pub full_name: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct LoginRequest {
pub username: String,
pub password: String,
}
#[derive(Debug, Deserialize)]
pub struct ChangePasswordRequest {
pub current_password: String,
pub new_password: String,
}
#[derive(Debug, Deserialize)]
pub struct ForgotPasswordRequest {
pub email: String,
}
#[derive(Debug, Deserialize)]
pub struct ResetPasswordRequest {
pub token: String,
pub new_password: String,
}
#[derive(Debug, Deserialize)]
pub struct VerifyEmailRequest {
pub token: String,
}
#[derive(Debug, Deserialize)]
pub struct RefreshTokenRequest {
pub refresh_token: String,
}
#[derive(Debug, Serialize)]
pub struct AuthResponse {
pub user: UserResponse,
pub tokens: TokenPair,
}
#[derive(Debug, Serialize)]
pub struct UserResponse {
pub id: uuid::Uuid,
pub username: String,
pub email: String,
pub display_name: Option<String>,
pub role: String,
pub email_verified: bool,
pub created_at: chrono::DateTime<chrono::Utc>,
}
#[derive(Debug, Serialize)]
pub struct RegisterResponse {
pub user_id: uuid::Uuid,
pub username: String,
pub email: String,
pub message: String,
}
#[derive(Debug, Serialize)]
pub struct LoginResponse {
pub access_token: String,
pub refresh_token: String,
pub token_type: String,
pub expires_in: u64,
pub user: UserInfo,
}
#[derive(Debug, Serialize)]
pub struct UserInfo {
pub id: uuid::Uuid,
pub username: String,
pub email: String,
pub full_name: Option<String>,
pub role: String,
pub email_verified: bool,
}
#[derive(Debug, Serialize)]
pub struct RefreshTokenResponse {
pub access_token: String,
pub token_type: String,
pub expires_in: u64,
}
impl From<User> for UserResponse {
fn from(user: User) -> Self {
Self {
id: user.id(),
username: user.username.clone(),
email: user.email.clone(),
display_name: user.display_name.clone(),
role: format!("{:?}", user.role),
email_verified: user.email_verified,
created_at: user.metadata.created_at,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_register_request_validation() {
let request = RegisterRequest {
username: "testuser".to_string(),
email: "test@example.com".to_string(),
password: "SecurePass123!".to_string(),
full_name: Some("Test User".to_string()),
};
assert_eq!(request.username, "testuser");
assert_eq!(request.email, "test@example.com");
assert!(request.full_name.is_some());
}
#[test]
fn test_user_response_conversion() {
let user_response = UserResponse {
id: uuid::Uuid::new_v4(),
username: "testuser".to_string(),
email: "test@example.com".to_string(),
display_name: Some("Test User".to_string()),
role: "User".to_string(),
email_verified: false,
created_at: chrono::Utc::now(),
};
assert_eq!(user_response.username, "testuser");
assert!(!user_response.email_verified);
}
}