rust_woocommerce/models/
customers.rs

1use chrono::NaiveDateTime;
2use serde::{Deserialize, Serialize};
3
4use crate::controllers::customers::{CreateCustomer, UpdateCustomer};
5use crate::controllers::Entity;
6
7use super::MetaData;
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Customer {
10    /// Unique identifier for the resource
11    pub id: i32,
12    /// The date the customer was created, in the site's timezone.
13    pub date_created: NaiveDateTime,
14    /// The date the customer was created, as GMT
15    pub date_modified: NaiveDateTime,
16    /// The date the customer was last modified, as GMT.
17    pub date_modified_gmt: NaiveDateTime,
18    /// The email address for the customer
19    pub email: String,
20    /// Customer first name.    
21    pub first_name: String,
22    /// Customer last name.
23    pub last_name: String,
24    /// Customer role.
25    pub role: Role,
26    /// Customer login name.
27    pub username: String,
28    /// List of billing address data.    
29    pub billing: Billing,
30    /// List of shipping address data.
31    pub shipping: Shipping,
32    /// Is the customer a paying customer
33    pub is_paying_customer: bool,
34    /// Avatar URL
35    pub avatar_url: String,
36    /// Meta data.
37    pub meta_data: Vec<MetaData>,
38}
39impl Entity for Customer {
40    fn endpoint() -> String {
41        String::from("customers/")
42    }
43    fn child_endpoint(parent_id: i32) -> String {
44        let _ = parent_id;
45        String::new()
46    }
47}
48#[derive(Debug, Clone, Serialize, Deserialize, Default)]
49pub struct Billing {
50    /// First name.
51    pub first_name: String,
52    /// Last name.
53    pub last_name: String,
54    /// Company name.
55    pub company: String,
56    /// Address line 1
57    pub address_1: String,
58    /// Address line 2
59    pub address_2: String,
60    /// City name.
61    pub city: String,
62    /// ISO code or name of the state, province or district.
63    pub state: String,
64    /// Postal code.
65    pub postcode: String,
66    /// ISO code of the country.
67    pub country: String,
68    /// Email address.
69    pub email: String,
70    /// Phone number.
71    pub phone: String,
72}
73#[derive(Debug, Clone, Serialize, Deserialize, Default)]
74pub struct Shipping {
75    /// First name.
76    pub first_name: String,
77    /// Last name.
78    pub last_name: String,
79    /// Company name.
80    pub company: String,
81    /// Address line 1
82    pub address_1: String,
83    /// Address line 2
84    pub address_2: String,
85    /// City name.
86    pub city: String,
87    /// ISO code or name of the state, province or district.
88    pub state: String,
89    /// Postal code.
90    pub postcode: String,
91    /// ISO code of the country.
92    pub country: String,
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize, Default)]
96#[serde(rename_all = "snake_case")]
97pub enum Role {
98    Administrator,
99    Editor,
100    Author,
101    Contributor,
102    Subscriber,
103    #[default]
104    Customer,
105    ShopManager,
106}
107impl Customer {
108    pub fn create<T: ToString>(email: T) -> CreateCustomer {
109        CreateCustomer::new(email)
110    }
111    pub fn update() -> UpdateCustomer {
112        UpdateCustomer::default()
113    }
114}