Skip to content

Commit 3061ad2

Browse files
committed
Add synchronize single booking method
1 parent e1d5b27 commit 3061ad2

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

Modules/Sources/NetworkingCore/Remote/OrdersRemote.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ public class OrdersRemote: Remote {
129129

130130
let parameters: [String: Any] = [
131131
ParameterKeys.include: Set(orderIDs).map(String.init).joined(separator: ","),
132-
ParameterKeys.fields: ParameterValues.fieldValues,
133-
ParameterKeys.perPage: String(orderIDs.count)
132+
ParameterKeys.fields: ParameterValues.fieldValues
134133
]
135134

136135
let path = Constants.ordersPath

Modules/Sources/Yosemite/Stores/BookingStore.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,45 @@ private extension BookingStore {
103103
}
104104
}
105105

106+
func synchronizeBooking(
107+
siteID: Int64,
108+
bookingID: Int64,
109+
onCompletion: @escaping (Result<Void, Error>) -> Void
110+
) {
111+
enum SynchronizeBookingError: Error {
112+
case bookingIsMissing
113+
}
114+
115+
Task { @MainActor in
116+
do {
117+
let booking = try await remote.loadBooking(
118+
bookingID: bookingID,
119+
siteID: siteID
120+
)
121+
122+
guard let booking else {
123+
onCompletion(.failure(SynchronizeBookingError.bookingIsMissing))
124+
return
125+
}
126+
127+
let orders = try await ordersRemote.loadOrders(
128+
for: siteID,
129+
orderIDs: [booking.orderID]
130+
)
131+
132+
await upsertStoredBookingsInBackground(
133+
readOnlyBookings: [booking],
134+
readOnlyOrders: orders,
135+
siteID: siteID
136+
)
137+
138+
onCompletion(.success(()))
139+
} catch {
140+
onCompletion(.failure(error))
141+
}
142+
}
143+
}
144+
106145
/// Checks if the store already has any bookings.
107146
/// Returns `false` if the store has no bookings.
108147
///

0 commit comments

Comments
 (0)