exercises

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

address.rs (2152B)


      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 UserAddress {
      7     pub id: i32,
      8     pub uuid: Uuid,
      9     pub user_id: i32,
     10     pub address_type: String,
     11     pub address_label: Option<String>,
     12     pub first_name: String,
     13     pub last_name: String,
     14     pub address_line1: String,
     15     pub address_line2: Option<String>,
     16     pub city: String,
     17     pub state: String,
     18     pub postal_code: String,
     19     pub country: String,
     20     pub phone: Option<String>,
     21     pub is_default: bool,
     22     pub is_active: bool,
     23     pub created_at: DateTime<Utc>,
     24     pub updated_at: DateTime<Utc>,
     25 }
     26 
     27 #[derive(Debug, Deserialize)]
     28 pub struct AddAddressRequest {
     29     pub address_type: String,
     30     pub address_label: Option<String>,
     31     pub first_name: String,
     32     pub last_name: String,
     33     pub address_line1: String,
     34     pub address_line2: Option<String>,
     35     pub city: String,
     36     pub state: String,
     37     pub postal_code: String,
     38     pub country: String,
     39     pub phone: Option<String>,
     40     pub is_default: Option<bool>,
     41 }
     42 
     43 #[derive(Debug, Serialize)]
     44 pub struct AddressResponse {
     45     pub eid: Uuid,
     46     pub address_type: String,
     47     pub address_label: Option<String>,
     48     pub first_name: String,
     49     pub last_name: String,
     50     pub address_line1: String,
     51     pub address_line2: Option<String>,
     52     pub city: String,
     53     pub state: String,
     54     pub postal_code: String,
     55     pub country: String,
     56     pub phone: Option<String>,
     57     pub is_default: bool,
     58 }
     59 
     60 impl From<UserAddress> for AddressResponse {
     61     fn from(addr: UserAddress) -> Self {
     62         Self {
     63             eid: addr.uuid,
     64             address_type: addr.address_type,
     65             address_label: addr.address_label,
     66             first_name: addr.first_name,
     67             last_name: addr.last_name,
     68             address_line1: addr.address_line1,
     69             address_line2: addr.address_line2,
     70             city: addr.city,
     71             state: addr.state,
     72             postal_code: addr.postal_code,
     73             country: addr.country,
     74             phone: addr.phone,
     75             is_default: addr.is_default,
     76         }
     77     }
     78 }