rust_woocommerce/controllers/
customers.rs1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::{Billing, MetaData, Shipping};
5
6#[skip_serializing_none]
7#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8pub struct CreateCustomer {
9 email: String,
11 first_name: Option<String>,
13 last_name: Option<String>,
15 username: Option<String>,
17 password: Option<String>,
19 billing: Option<Billing>,
21 shipping: Option<Shipping>,
23 meta_data: Option<Vec<MetaData>>,
25}
26
27impl CreateCustomer {
28 pub fn new<T: ToString>(email: T) -> Self {
30 CreateCustomer {
31 email: email.to_string(),
32 ..Default::default()
33 }
34 }
35 pub fn first_name(mut self, first_name: impl Into<String>) -> Self {
37 let _ = self.first_name.insert(first_name.into());
38 self
39 }
40 pub fn last_name(mut self, last_name: impl Into<String>) -> Self {
42 let _ = self.last_name.insert(last_name.into());
43 self
44 }
45 pub fn username(mut self, username: impl Into<String>) -> Self {
47 let _ = self.username.insert(username.into());
48 self
49 }
50 pub fn password(mut self, password: impl Into<String>) -> Self {
52 let _ = self.password.insert(password.into());
53 self
54 }
55 pub fn billing_first_name(mut self, first_name: impl Into<String>) -> Self {
57 self.billing.get_or_insert(Billing::default()).first_name = first_name.into();
58 self
59 }
60 pub fn billing_last_name(mut self, last_name: impl Into<String>) -> Self {
62 self.billing.get_or_insert(Billing::default()).last_name = last_name.into();
63 self
64 }
65 pub fn billing_company(mut self, company: impl Into<String>) -> Self {
67 self.billing.get_or_insert(Billing::default()).company = company.into();
68 self
69 }
70 pub fn billing_address_1(mut self, address_1: impl Into<String>) -> Self {
72 self.billing.get_or_insert(Billing::default()).address_1 = address_1.into();
73 self
74 }
75 pub fn billing_address_2(mut self, address_2: impl Into<String>) -> Self {
77 self.billing.get_or_insert(Billing::default()).address_2 = address_2.into();
78 self
79 }
80 pub fn billing_city(mut self, city: impl Into<String>) -> Self {
82 self.billing.get_or_insert(Billing::default()).city = city.into();
83 self
84 }
85 pub fn billing_state(mut self, state: impl Into<String>) -> Self {
87 self.billing.get_or_insert(Billing::default()).state = state.into();
88 self
89 }
90 pub fn billing_postcode(mut self, postcode: impl Into<String>) -> Self {
92 self.billing.get_or_insert(Billing::default()).postcode = postcode.into();
93 self
94 }
95 pub fn billing_country(mut self, country: impl Into<String>) -> Self {
97 self.billing.get_or_insert(Billing::default()).country = country.into();
98 self
99 }
100 pub fn billing_email(mut self, email: impl Into<String>) -> Self {
102 self.billing.get_or_insert(Billing::default()).email = email.into();
103 self
104 }
105 pub fn billing_phone(mut self, phone: impl Into<String>) -> Self {
107 self.billing.get_or_insert(Billing::default()).phone = phone.into();
108 self
109 }
110 pub fn shipping_first_name(mut self, first_name: impl Into<String>) -> Self {
112 self.shipping.get_or_insert(Shipping::default()).first_name = first_name.into();
113 self
114 }
115 pub fn shipping_last_name(mut self, last_name: impl Into<String>) -> Self {
117 self.shipping.get_or_insert(Shipping::default()).last_name = last_name.into();
118 self
119 }
120 pub fn shipping_company(mut self, company: impl Into<String>) -> Self {
122 self.shipping.get_or_insert(Shipping::default()).company = company.into();
123 self
124 }
125 pub fn shipping_address_1(mut self, address_1: impl Into<String>) -> Self {
127 self.shipping.get_or_insert(Shipping::default()).address_1 = address_1.into();
128 self
129 }
130 pub fn shipping_address_2(mut self, address_2: impl Into<String>) -> Self {
132 self.shipping.get_or_insert(Shipping::default()).address_2 = address_2.into();
133 self
134 }
135 pub fn shipping_city(mut self, city: impl Into<String>) -> Self {
137 self.shipping.get_or_insert(Shipping::default()).city = city.into();
138 self
139 }
140 pub fn shipping_state(mut self, state: impl Into<String>) -> Self {
142 self.shipping.get_or_insert(Shipping::default()).state = state.into();
143 self
144 }
145 pub fn shipping_postcode(mut self, postcode: impl Into<String>) -> Self {
147 self.shipping.get_or_insert(Shipping::default()).postcode = postcode.into();
148 self
149 }
150 pub fn shipping_country(mut self, country: impl Into<String>) -> Self {
152 self.shipping.get_or_insert(Shipping::default()).country = country.into();
153 self
154 }
155 pub fn meta_data(mut self, key: impl Into<String>, value: impl serde::Serialize) -> Self {
157 self.meta_data.get_or_insert(vec![]).push(MetaData {
158 id: None,
159 key: key.into(),
160 value: serde_json::json!(value),
161 });
162 self
163 }
164}
165#[skip_serializing_none]
166#[derive(Debug, Clone, Serialize, Deserialize, Default)]
167pub struct UpdateCustomer {
168 id: Option<i32>,
170 email: Option<String>,
172 first_name: Option<String>,
174 last_name: Option<String>,
176 username: Option<String>,
178 password: Option<String>,
180 billing: Option<Billing>,
182 shipping: Option<Shipping>,
184 meta_data: Option<Vec<MetaData>>,
186}
187impl UpdateCustomer {
188 pub fn id(mut self, id: i32) -> Self {
190 let _ = self.id.insert(id);
191 self
192 }
193 pub fn email(mut self, email: impl Into<String>) -> Self {
195 let _ = self.email.insert(email.into());
196 self
197 }
198 pub fn first_name(mut self, first_name: impl Into<String>) -> Self {
200 let _ = self.first_name.insert(first_name.into());
201 self
202 }
203 pub fn last_name(mut self, last_name: impl Into<String>) -> Self {
205 let _ = self.last_name.insert(last_name.into());
206 self
207 }
208 pub fn username(mut self, username: impl Into<String>) -> Self {
210 let _ = self.username.insert(username.into());
211 self
212 }
213 pub fn password(mut self, password: impl Into<String>) -> Self {
215 let _ = self.password.insert(password.into());
216 self
217 }
218 pub fn billing_first_name(mut self, first_name: impl Into<String>) -> Self {
220 self.billing.get_or_insert(Billing::default()).first_name = first_name.into();
221 self
222 }
223 pub fn billing_last_name(mut self, last_name: impl Into<String>) -> Self {
225 self.billing.get_or_insert(Billing::default()).last_name = last_name.into();
226 self
227 }
228 pub fn billing_company(mut self, company: impl Into<String>) -> Self {
230 self.billing.get_or_insert(Billing::default()).company = company.into();
231 self
232 }
233 pub fn billing_address_1(mut self, address_1: impl Into<String>) -> Self {
235 self.billing.get_or_insert(Billing::default()).address_1 = address_1.into();
236 self
237 }
238 pub fn billing_address_2(mut self, address_2: impl Into<String>) -> Self {
240 self.billing.get_or_insert(Billing::default()).address_2 = address_2.into();
241 self
242 }
243 pub fn billing_city(mut self, city: impl Into<String>) -> Self {
245 self.billing.get_or_insert(Billing::default()).city = city.into();
246 self
247 }
248 pub fn billing_state(mut self, state: impl Into<String>) -> Self {
250 self.billing.get_or_insert(Billing::default()).state = state.into();
251 self
252 }
253 pub fn billing_postcode(mut self, postcode: impl Into<String>) -> Self {
255 self.billing.get_or_insert(Billing::default()).postcode = postcode.into();
256 self
257 }
258 pub fn billing_country(mut self, country: impl Into<String>) -> Self {
260 self.billing.get_or_insert(Billing::default()).country = country.into();
261 self
262 }
263 pub fn billing_email(mut self, email: impl Into<String>) -> Self {
265 self.billing.get_or_insert(Billing::default()).email = email.into();
266 self
267 }
268 pub fn billing_phone(mut self, phone: impl Into<String>) -> Self {
270 self.billing.get_or_insert(Billing::default()).phone = phone.into();
271 self
272 }
273 pub fn shipping_first_name(mut self, first_name: impl Into<String>) -> Self {
275 self.shipping.get_or_insert(Shipping::default()).first_name = first_name.into();
276 self
277 }
278 pub fn shipping_last_name(mut self, last_name: impl Into<String>) -> Self {
280 self.shipping.get_or_insert(Shipping::default()).last_name = last_name.into();
281 self
282 }
283 pub fn shipping_company(mut self, company: impl Into<String>) -> Self {
285 self.shipping.get_or_insert(Shipping::default()).company = company.into();
286 self
287 }
288 pub fn shipping_address_1(mut self, address_1: impl Into<String>) -> Self {
290 self.shipping.get_or_insert(Shipping::default()).address_1 = address_1.into();
291 self
292 }
293 pub fn shipping_address_2(mut self, address_2: impl Into<String>) -> Self {
295 self.shipping.get_or_insert(Shipping::default()).address_2 = address_2.into();
296 self
297 }
298 pub fn shipping_city(mut self, city: impl Into<String>) -> Self {
300 self.shipping.get_or_insert(Shipping::default()).city = city.into();
301 self
302 }
303 pub fn shipping_state(mut self, state: impl Into<String>) -> Self {
305 self.shipping.get_or_insert(Shipping::default()).state = state.into();
306 self
307 }
308 pub fn shipping_postcode(mut self, postcode: impl Into<String>) -> Self {
310 self.shipping.get_or_insert(Shipping::default()).postcode = postcode.into();
311 self
312 }
313 pub fn shipping_country(mut self, country: impl Into<String>) -> Self {
315 self.shipping.get_or_insert(Shipping::default()).country = country.into();
316 self
317 }
318 pub fn meta_data(mut self, key: impl Into<String>, value: impl serde::Serialize) -> Self {
320 self.meta_data.get_or_insert(vec![]).push(MetaData {
321 id: None,
322 key: key.into(),
323 value: serde_json::json!(value),
324 });
325 self
326 }
327}