exercises

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

user.rs (1939B)


      1 use chrono::{DateTime, Utc};
      2 use serde::{Deserialize, Serialize};
      3 use uuid::Uuid;
      4 
      5 #[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
      6 pub struct User {
      7     pub id: i32,
      8     pub uuid: Uuid,
      9     pub email: String,
     10     #[serde(skip_serializing)]
     11     pub password_hash: String,
     12     pub first_name: Option<String>,
     13     pub last_name: Option<String>,
     14     pub phone: Option<String>,
     15     pub is_active: bool,
     16     pub is_verified: bool,
     17     pub email_verification_token: Option<String>,
     18     pub email_verified_at: Option<DateTime<Utc>>,
     19     pub password_reset_token: Option<String>,
     20     pub password_reset_expires_at: Option<DateTime<Utc>>,
     21     pub last_login_at: Option<DateTime<Utc>>,
     22     pub created_at: DateTime<Utc>,
     23     pub updated_at: DateTime<Utc>,
     24 }
     25 
     26 #[derive(Debug, Deserialize)]
     27 pub struct RegisterRequest {
     28     pub email: String,
     29     pub password: String,
     30     pub first_name: Option<String>,
     31     pub last_name: Option<String>,
     32     pub phone: Option<String>,
     33 }
     34 
     35 #[derive(Debug, Deserialize)]
     36 pub struct LoginRequest {
     37     pub email: String,
     38     pub password: String,
     39 }
     40 
     41 #[derive(Debug, Serialize)]
     42 pub struct UserResponse {
     43     pub eid: Uuid,
     44     pub email: String,
     45     pub first_name: Option<String>,
     46     pub last_name: Option<String>,
     47     pub phone: Option<String>,
     48     pub is_verified: bool,
     49     pub created_at: DateTime<Utc>,
     50 }
     51 
     52 impl From<User> for UserResponse {
     53     fn from(user: User) -> Self {
     54         Self {
     55             eid: user.uuid,
     56             email: user.email,
     57             first_name: user.first_name,
     58             last_name: user.last_name,
     59             phone: user.phone,
     60             is_verified: user.is_verified,
     61             created_at: user.created_at,
     62         }
     63     }
     64 }
     65 
     66 #[derive(Debug, Deserialize)]
     67 pub struct UpdateProfileRequest {
     68     pub avatar_url: Option<String>,
     69     pub date_of_birth: Option<chrono::NaiveDate>,
     70     pub email_notifications: Option<bool>,
     71     pub marketing_emails: Option<bool>,
     72 }