Skip to content

Commit 28826ce

Browse files
committed
Add billing & shipping params to Customer model
1 parent 1640d5c commit 28826ce

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

Networking/Networking/Model/Customer.swift

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,51 @@ struct Customer: Codable {
1313
let email: String
1414

1515
/// Customer first name
16-
let firstName: String
16+
let firstName: String?
1717

1818
/// Customer last name
19-
let lastName: String
20-
// TODO: Check why both billing and shipping are making the decoder fail.
19+
let lastName: String?
20+
2121
/// List of billing address data
22-
//let billing: [String]
22+
let billing: Address?
2323

2424
/// List of shipping address data
25-
//let shipping: [String]
25+
let shipping: Address?
2626

2727
/// Customer struct initializer
2828
///
2929
public init(customerID: Int64,
3030
email: String,
31-
firstName: String,
32-
lastName: String) {
31+
firstName: String?,
32+
lastName: String?,
33+
billing: Address?,
34+
shipping: Address?) {
3335
self.customerID = customerID
3436
self.email = email
3537
self.firstName = firstName
3638
self.lastName = lastName
39+
self.billing = billing
40+
self.shipping = shipping
3741
}
3842

3943
/// Public initializer for the Customer
4044
///
4145
public init(from decoder: Decoder) throws {
4246
let container = try decoder.container(keyedBy: CodingKeys.self)
47+
4348
let customerID = try container.decode(Int64.self, forKey: .customerID)
4449
let email = try container.decode(String.self, forKey: .email)
4550
let firstName = try container.decodeIfPresent(String.self, forKey: .firstName) ?? ""
4651
let lastName = try container.decodeIfPresent(String.self, forKey: .lastName) ?? ""
52+
let billing = try? container.decode(Address.self, forKey: .billing)
53+
let shipping = try? container.decode(Address.self, forKey: .shipping)
4754

4855
self.init(customerID: customerID,
49-
email: email,
50-
firstName: firstName,
51-
lastName: lastName
56+
email: email,
57+
firstName: firstName,
58+
lastName: lastName,
59+
billing: billing,
60+
shipping: shipping
5261
)
5362
}
5463
}
@@ -61,5 +70,7 @@ extension Customer {
6170
case email
6271
case firstName = "first_name"
6372
case lastName = "last_name"
73+
case billing
74+
case shipping
6475
}
6576
}

0 commit comments

Comments
 (0)