Skip to content

Commit 061882d

Browse files
authored
[Bookings] Add Yosemite models for booking info (#16245)
2 parents 17d34bf + 086b94f commit 061882d

17 files changed

+335
-16
lines changed

Modules/Sources/Fakes/Networking.generated.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ extension Networking.Booking {
339339
startDate: .fake(),
340340
statusKey: .fake(),
341341
localTimezone: .fake(),
342-
currency: .fake()
342+
currency: .fake(),
343+
orderInfo: .fake()
343344
)
344345
}
345346
}

Modules/Sources/Networking/Model/Bookings/Booking.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public struct Booking: Codable, GeneratedCopiable, Hashable, GeneratedFakeable {
2222
public let statusKey: String
2323
public let localTimezone: String
2424
public let currency: String
25-
2625
// periphery: ignore - to be used later
26+
public let orderInfo: BookingOrderInfo?
27+
2728
public var bookingStatus: BookingStatus {
2829
return BookingStatus(rawValue: statusKey) ?? .unknown
2930
}
@@ -47,7 +48,8 @@ public struct Booking: Codable, GeneratedCopiable, Hashable, GeneratedFakeable {
4748
startDate: Date,
4849
statusKey: String,
4950
localTimezone: String,
50-
currency: String) {
51+
currency: String,
52+
orderInfo: BookingOrderInfo?) {
5153
self.siteID = siteID
5254
self.bookingID = bookingID
5355
self.allDay = allDay
@@ -66,6 +68,7 @@ public struct Booking: Codable, GeneratedCopiable, Hashable, GeneratedFakeable {
6668
self.statusKey = statusKey
6769
self.localTimezone = localTimezone
6870
self.currency = currency
71+
self.orderInfo = orderInfo
6972
}
7073

7174
/// The public initializer for Booking.
@@ -99,6 +102,7 @@ public struct Booking: Codable, GeneratedCopiable, Hashable, GeneratedFakeable {
99102
let statusKey = try container.decode(String.self, forKey: .statusKey)
100103
let localTimezone = try container.decode(String.self, forKey: .localTimezone)
101104
let currency = try container.decode(String.self, forKey: .currency)
105+
let orderInfo: BookingOrderInfo? = nil // to be prefilled when synced
102106

103107
self.init(siteID: siteID,
104108
bookingID: bookingID,
@@ -117,7 +121,8 @@ public struct Booking: Codable, GeneratedCopiable, Hashable, GeneratedFakeable {
117121
startDate: startDate,
118122
statusKey: statusKey,
119123
localTimezone: localTimezone,
120-
currency: currency)
124+
currency: currency,
125+
orderInfo: orderInfo)
121126
}
122127

123128
public func encode(to encoder: Encoder) throws {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Foundation
2+
3+
public struct BookingCustomerInfo: Hashable {
4+
public let billingAddress: Address
5+
6+
public init(billingAddress: Address) {
7+
self.billingAddress = billingAddress
8+
}
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// periphery:ignore:all
2+
import Foundation
3+
4+
public struct BookingOrderInfo: Hashable {
5+
public let statusKey: String
6+
public let paymentInfo: BookingPaymentInfo?
7+
public let customerInfo: BookingCustomerInfo?
8+
public let productInfo: BookingProductInfo?
9+
10+
public init(statusKey: String,
11+
paymentInfo: BookingPaymentInfo?,
12+
customerInfo: BookingCustomerInfo?,
13+
productInfo: BookingProductInfo?) {
14+
self.statusKey = statusKey
15+
self.paymentInfo = paymentInfo
16+
self.customerInfo = customerInfo
17+
self.productInfo = productInfo
18+
}
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
3+
public struct BookingPaymentInfo: Hashable {
4+
public let paymentMethodID: String
5+
public let paymentMethodTitle: String
6+
public let subtotal: String
7+
public let subtotalTax: String
8+
public let total: String
9+
public let totalTax: String
10+
11+
public init(paymentMethodID: String,
12+
paymentMethodTitle: String,
13+
subtotal: String,
14+
subtotalTax: String,
15+
total: String,
16+
totalTax: String) {
17+
self.paymentMethodID = paymentMethodID
18+
self.paymentMethodTitle = paymentMethodTitle
19+
self.subtotal = subtotal
20+
self.subtotalTax = subtotalTax
21+
self.total = total
22+
self.totalTax = totalTax
23+
}
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Foundation
2+
3+
public struct BookingProductInfo: Hashable {
4+
public let name: String
5+
6+
public init(name: String) {
7+
self.name = name
8+
}
9+
}

Modules/Sources/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ extension Networking.Booking {
447447
startDate: CopiableProp<Date> = .copy,
448448
statusKey: CopiableProp<String> = .copy,
449449
localTimezone: CopiableProp<String> = .copy,
450-
currency: CopiableProp<String> = .copy
450+
currency: CopiableProp<String> = .copy,
451+
orderInfo: NullableCopiableProp<BookingOrderInfo> = .copy
451452
) -> Networking.Booking {
452453
let siteID = siteID ?? self.siteID
453454
let bookingID = bookingID ?? self.bookingID
@@ -467,6 +468,7 @@ extension Networking.Booking {
467468
let statusKey = statusKey ?? self.statusKey
468469
let localTimezone = localTimezone ?? self.localTimezone
469470
let currency = currency ?? self.currency
471+
let orderInfo = orderInfo ?? self.orderInfo
470472

471473
return Networking.Booking(
472474
siteID: siteID,
@@ -486,7 +488,8 @@ extension Networking.Booking {
486488
startDate: startDate,
487489
statusKey: statusKey,
488490
localTimezone: localTimezone,
489-
currency: currency
491+
currency: currency,
492+
orderInfo: orderInfo
490493
)
491494
}
492495
}

Modules/Sources/NetworkingCore/Model/Address.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Codegen
33

44
/// Represents an Address Entity.
55
///
6-
public struct Address: Codable, Sendable, GeneratedFakeable, GeneratedCopiable {
6+
public struct Address: Codable, Sendable, GeneratedFakeable, GeneratedCopiable, Hashable {
77
public let firstName: String
88
public let lastName: String
99
public let company: String?

Modules/Sources/Yosemite/Model/Booking/Booking+ReadOnlyConvertible.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Foundation
22
import Storage
33

4-
54
// MARK: - Storage.Booking: ReadOnlyConvertible
65
//
76
extension Storage.Booking: ReadOnlyConvertible {
@@ -49,6 +48,7 @@ extension Storage.Booking: ReadOnlyConvertible {
4948
startDate: startDate ?? Date(),
5049
statusKey: statusKey ?? "",
5150
localTimezone: localTimezone ?? "",
52-
currency: currency ?? "USD")
51+
currency: currency ?? "USD",
52+
orderInfo: orderInfo?.toReadOnly())
5353
}
5454
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Foundation
2+
import Storage
3+
4+
// MARK: - Storage.BookingCustomerInfo: ReadOnlyConvertible
5+
//
6+
extension Storage.BookingCustomerInfo: ReadOnlyConvertible {
7+
public func update(with customerInfo: Yosemite.BookingCustomerInfo) {
8+
billingAddress1 = customerInfo.billingAddress.address1
9+
billingAddress2 = customerInfo.billingAddress.address2
10+
billingCity = customerInfo.billingAddress.city
11+
billingCompany = customerInfo.billingAddress.company
12+
billingCountry = customerInfo.billingAddress.country
13+
billingEmail = customerInfo.billingAddress.email
14+
billingFirstName = customerInfo.billingAddress.firstName
15+
billingLastName = customerInfo.billingAddress.lastName
16+
billingPhone = customerInfo.billingAddress.phone
17+
billingPostcode = customerInfo.billingAddress.postcode
18+
billingState = customerInfo.billingAddress.state
19+
}
20+
21+
public func toReadOnly() -> Yosemite.BookingCustomerInfo {
22+
let address = Yosemite.Address(firstName: billingFirstName ?? "",
23+
lastName: billingLastName ?? "",
24+
company: billingCompany,
25+
address1: billingAddress1 ?? "",
26+
address2: billingAddress2,
27+
city: billingCity ?? "",
28+
state: billingState ?? "",
29+
postcode: billingPostcode ?? "",
30+
country: billingCountry ?? "",
31+
phone: billingPhone,
32+
email: billingEmail)
33+
return .init(billingAddress: address)
34+
}
35+
}

0 commit comments

Comments
 (0)