1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
use serde::{Serialize, Deserialize, Serializer, Deserializer};
use chrono::{DateTime, Local, NaiveDateTime, TimeZone};
use sqlx::{Encode, Decode, FromRow, TypeInfo};
use std::fmt;
#[derive(Clone)]
pub struct LocalDateTime(DateTime<Local>);
impl Serialize for LocalDateTime {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.collect_str(&format!("{}", self.0.format("%YYYY-%mm-%ddT%H:%M:%SZ"))) }
}impl<'de> Deserialize<'de> for LocalDateTime {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
let dt = DateTime::parse_from_rfc3339(&s).unwrap();
Ok(LocalDateTime(dt.into()))
}
}
impl fmt::Debug for LocalDateTime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "LocalDateTime({:?})", self.0)
}
}
impl Default for LocalDateTime {
fn default() -> Self {
let default_datetime = NaiveDateTime::from_timestamp_opt(0, 0).unwrap_or_default();
let local_datetime = Local.from_local_datetime(&default_datetime).unwrap();
LocalDateTime(local_datetime)
}
}
impl From<DateTime<Local>> for LocalDateTime {
fn from(value: DateTime<Local>) -> Self {
Self(value)
}
}
impl From<LocalDateTime> for DateTime<Local> {
fn from(value: LocalDateTime) -> Self {
value.0
}
}
#[derive(Deserialize, Debug)]
pub struct CourierInfo {
pub name: Option<String>,
pub vehicle_type: Option<String>,
pub phone_number: Option<String>,
pub location: Option<LatLng>,
pub img_href: Option<String>,
}
#[derive(Deserialize, Debug)]
pub struct LatLng {
pub lat: f64,
pub lng: f64,
}
#[derive(Deserialize, Debug)]
pub struct RelatedDelivery {
pub id: String,
pub relationship: String,
}
#[derive(Deserialize, Debug)]
pub struct ManifestInfo {
pub reference: Option<String>,
pub description: String,
pub total_value: u32,
}
#[derive(Deserialize, Debug)]
pub struct WaypointInfo {
pub name: String,
pub phone_number: String,
pub address: String,
pub detailed_address: StructuredAddress,
pub notes: Option<String>,
pub seller_notes: Option<String>,
pub courier_notes: Option<String>,
pub location: LatLng,
pub verification: Option<VerificationProof>,
pub verification_requirements: Option<VerificationRequirement>,
pub external_store_id: Option<String>,
}
#[derive(Deserialize, Debug, Serialize, Default, Clone)]
pub struct StructuredAddress {
pub street_address_1: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub street_address_2: Option<String>,
pub city: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub state: String,
pub zip_code: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub country: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sublocality_level_1: Option<String>,
}
impl fmt::Display for StructuredAddress {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut address = self.street_address_1.clone();
if let Some(street_address_2) = &self.street_address_2 {
address.push_str(&format!(", {}", street_address_2));
}
write!(
f,
"{}, {}, {}, {}",
address,
self.city,
self.state,
self.zip_code
)?;
if let Some(sublocality_level_1) = &self.sublocality_level_1 {
write!(f, ", {}", sublocality_level_1)?;
}
if let Some(country) = &self.country {
write!(f, ", {}", country)?;
}
Ok(())
}
}
#[derive(Deserialize, Debug)]
pub struct VerificationProof {
pub signature: SignatureProof,
pub barcodes: Vec<BarcodeRequirement>,
pub picture: PictureProof,
pub identification: IdentificationProof,
pub pin_code: PincodeProof,
}
#[derive(Deserialize, Debug)]
pub struct SignatureProof {
pub image_url: String,
pub signer_name: String,
pub signer_relationship: String,
}
#[derive(Deserialize, Debug)]
pub struct PictureProof {
pub image_url: String,
}
#[derive(Deserialize, Debug)]
pub struct IdentificationProof {
pub min_age_verified: bool,
}
#[derive(Deserialize, Debug)]
pub struct PincodeProof {
pub entered: String,
}
#[derive(Serialize, Default, Debug, Deserialize, Clone)]
pub struct ManifestItem {
pub name: String,
pub quantity: u32,
#[serde(skip_serializing_if = "String::is_empty")]
pub size: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub dimensions: Option<Dimensions>,
#[serde(skip_serializing_if = "Option::is_none")]
pub price: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub must_be_upright: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub weight: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub perishability: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub preparation_time: Option<u32>,
}
impl ManifestItem {
pub fn new<T: Into<String>>(name: T, quantity: u32, size: T) -> Self {
ManifestItem {
name: name.into(),
quantity,
size: size.into(),
..Default::default()
}
}
}
#[derive(Serialize, Debug, Deserialize)]
pub struct VerificationRequirement {
#[serde(skip_serializing_if = "Option::is_none")]
pub signature: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signature_requirement: Option<SignatureRequirement>,
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::default", deserialize_with = "null_to_default")]
pub barcodes: Vec<BarcodeRequirement>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pincode: Option<PincodeRequirement>,
#[serde(skip_serializing_if = "Option::is_none")]
pub package: Option<PackageRequirement>,
#[serde(skip_serializing_if = "Option::is_none")]
pub identification: Option<IdentificationRequirement>,
#[serde(skip_serializing_if = "Option::is_none")]
pub picture: Option<bool>,
}
#[derive(Serialize, Debug, Deserialize, Clone)]
pub struct Dimensions {
pub length: Option<u32>,
pub height: Option<u32>,
pub depth: Option<u32>,
}
#[derive(Serialize, Debug, Deserialize)]
pub struct SignatureRequirement {
pub enabled: bool,
pub collect_signer_name: bool,
pub collect_signer_relationship: bool,
}
#[derive(Serialize, Debug, Deserialize, Clone)]
pub struct BarcodeRequirement {
#[serde(default)]
pub value: String,
#[serde(default)]
pub type_of_barcode: String,
}
#[derive(Serialize, Debug, Deserialize)]
pub struct PincodeRequirement {
pub enabled: bool,
pub value: String,
}
#[derive(Serialize, Debug, Deserialize)]
pub struct PackageRequirement {
pub bag_count: u32,
pub drink_count: u32,
}
#[derive(Serialize, Debug, Deserialize)]
pub struct IdentificationRequirement {
pub min_age: u32,
}
#[derive(Serialize, Debug, Clone)]
pub struct TestSpecifications {
pub robo_courier_specification: RoboCourierSpecification,
}
#[derive(Serialize, Debug, Clone)]
pub struct RoboCourierSpecification {
pub mode: String,
}
fn null_to_default<'de, D, T>(d: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
T: Default + Deserialize<'de>,
{
let opt = Option::deserialize(d)?;
let val = opt.unwrap_or_else(T::default);
Ok(val)
}