rust_woocommerce/models/
customers.rs1use 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 pub id: i32,
12 pub date_created: NaiveDateTime,
14 pub date_modified: NaiveDateTime,
16 pub date_modified_gmt: NaiveDateTime,
18 pub email: String,
20 pub first_name: String,
22 pub last_name: String,
24 pub role: Role,
26 pub username: String,
28 pub billing: Billing,
30 pub shipping: Shipping,
32 pub is_paying_customer: bool,
34 pub avatar_url: String,
36 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 pub first_name: String,
52 pub last_name: String,
54 pub company: String,
56 pub address_1: String,
58 pub address_2: String,
60 pub city: String,
62 pub state: String,
64 pub postcode: String,
66 pub country: String,
68 pub email: String,
70 pub phone: String,
72}
73#[derive(Debug, Clone, Serialize, Deserialize, Default)]
74pub struct Shipping {
75 pub first_name: String,
77 pub last_name: String,
79 pub company: String,
81 pub address_1: String,
83 pub address_2: String,
85 pub city: String,
87 pub state: String,
89 pub postcode: String,
91 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}