Skip to content

Commit bfdc744

Browse files
committed
Merge branch 'trunk' into task/WOOMOB-1498-pos-surveys-complete-eligibility-checks
# Conflicts: # WooCommerce/Classes/POS/POSNotificationScheduler.swift # WooCommerce/WooCommerce.xcodeproj/project.pbxproj # WooCommerce/WooCommerceTests/POS/POSNotificationSchedulerTests.swift
2 parents d81986e + 17d34bf commit bfdc744

37 files changed

+2505
-250
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Foundation
2+
3+
/// Mapper: Booking
4+
///
5+
struct BookingMapper: Mapper {
6+
let siteID: Int64
7+
8+
func map(response: Data) throws -> Booking {
9+
let decoder = JSONDecoder()
10+
decoder.dateDecodingStrategy = .formatted(DateFormatter.Defaults.dateTimeFormatter)
11+
decoder.userInfo = [
12+
.siteID: siteID
13+
]
14+
if hasDataEnvelope(in: response) {
15+
return try decoder.decode(BookingEnvelope.self, from: response).booking
16+
} else {
17+
return try decoder.decode(Booking.self, from: response)
18+
}
19+
}
20+
}
21+
22+
private struct BookingEnvelope: Decodable {
23+
let booking: Booking
24+
25+
private enum CodingKeys: String, CodingKey {
26+
case booking = "data"
27+
}
28+
}

Modules/Sources/Networking/Remote/BookingsRemote.swift

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ public protocol BookingsRemoteProtocol {
1111
pageSize: Int,
1212
startDateBefore: String?,
1313
startDateAfter: String?,
14-
searchQuery: String?) async throws -> [Booking]
14+
searchQuery: String?,
15+
order: BookingsRemote.Order) async throws -> [Booking]
16+
17+
func loadBooking(bookingID: Int64,
18+
siteID: Int64) async throws -> Booking?
1519
}
1620

1721
/// Booking: Remote Endpoints
@@ -29,16 +33,19 @@ public final class BookingsRemote: Remote, BookingsRemoteProtocol {
2933
/// - startDateBefore: Filter bookings with start date before this timestamp.
3034
/// - startDateAfter: Filter bookings with start date after this timestamp.
3135
/// - searchQuery: Search query to filter bookings.
36+
/// - order: Sort order for bookings (ascending or descending).
3237
///
3338
public func loadAllBookings(for siteID: Int64,
3439
pageNumber: Int = Default.pageNumber,
3540
pageSize: Int = Default.pageSize,
3641
startDateBefore: String? = nil,
3742
startDateAfter: String? = nil,
38-
searchQuery: String? = nil) async throws -> [Booking] {
43+
searchQuery: String? = nil,
44+
order: Order) async throws -> [Booking] {
3945
var parameters = [
4046
ParameterKey.page: String(pageNumber),
41-
ParameterKey.perPage: String(pageSize)
47+
ParameterKey.perPage: String(pageSize),
48+
ParameterKey.order: order.rawValue
4249
]
4350

4451
if let startDateBefore = startDateBefore {
@@ -59,6 +66,24 @@ public final class BookingsRemote: Remote, BookingsRemoteProtocol {
5966

6067
return try await enqueue(request, mapper: mapper)
6168
}
69+
70+
public func loadBooking(
71+
bookingID: Int64,
72+
siteID: Int64
73+
) async throws -> Booking? {
74+
let path = "\(Path.bookings)/\(bookingID)"
75+
let request = JetpackRequest(
76+
wooApiVersion: .wcBookings,
77+
method: .get,
78+
siteID: siteID,
79+
path: path,
80+
availableAsRESTRequest: true
81+
)
82+
83+
let mapper = BookingMapper(siteID: siteID)
84+
85+
return try await enqueue(request, mapper: mapper)
86+
}
6287
}
6388

6489
// MARK: - Constants
@@ -69,6 +94,11 @@ public extension BookingsRemote {
6994
public static let pageNumber: Int = Remote.Default.firstPageNumber
7095
}
7196

97+
enum Order: String {
98+
case ascending = "asc"
99+
case descending = "desc"
100+
}
101+
72102
private enum Path {
73103
static let bookings = "bookings"
74104
}
@@ -79,5 +109,6 @@ public extension BookingsRemote {
79109
static let startDateBefore: String = "start_date_before"
80110
static let startDateAfter: String = "start_date_after"
81111
static let search: String = "search"
112+
static let order: String = "order"
82113
}
83114
}

Modules/Sources/NetworkingCore/Remote/OrdersRemote.swift

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import Foundation
22

3+
public protocol OrdersRemoteProtocol {
4+
func loadOrders(
5+
for siteID: Int64,
6+
orderIDs: [Int64]
7+
) async throws -> [Order]
8+
}
9+
310
/// Order: Remote Endpoints
411
///
5-
public class OrdersRemote: Remote {
12+
public class OrdersRemote: Remote, OrdersRemoteProtocol {
613
/// The source of the order creation.
714
public enum OrderCreationSource {
815
case storeManagement
@@ -111,6 +118,41 @@ public class OrdersRemote: Remote {
111118
enqueue(request, mapper: mapper, completion: completion)
112119
}
113120

121+
/// Retrieves specific `Order`s.
122+
///
123+
/// - Parameters:
124+
/// - siteID: Site for which we'll fetch remote orders.
125+
/// - orderIDs: The IDs of the orders to fetch.
126+
/// - Returns: Array of orders.
127+
/// - Throws: Network or parsing errors.
128+
///
129+
public func loadOrders(
130+
for siteID: Int64,
131+
orderIDs: [Int64]
132+
) async throws -> [Order] {
133+
guard !orderIDs.isEmpty else {
134+
return []
135+
}
136+
137+
let parameters: [String: Any] = [
138+
ParameterKeys.include: Set(orderIDs).map(String.init).joined(separator: ","),
139+
ParameterKeys.fields: ParameterValues.fieldValues
140+
]
141+
142+
let path = Constants.ordersPath
143+
let request = JetpackRequest(
144+
wooApiVersion: .mark3,
145+
method: .get,
146+
siteID: siteID,
147+
path: path,
148+
parameters: parameters,
149+
availableAsRESTRequest: true
150+
)
151+
let mapper = OrderListMapper(siteID: siteID)
152+
153+
return try await enqueue(request, mapper: mapper)
154+
}
155+
114156
/// Retrieves the notes for a specific `Order`
115157
///
116158
/// - Parameters:
@@ -534,6 +576,7 @@ public extension OrdersRemote {
534576
static let addedByUser: String = "added_by_user"
535577
static let customerNote: String = "customer_note"
536578
static let keyword: String = "search"
579+
static let include: String = "include"
537580
static let note: String = "note"
538581
static let page: String = "page"
539582
static let perPage: String = "per_page"

Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ extension Booking {
2121
@NSManaged public var statusKey: String?
2222
@NSManaged public var localTimezone: String?
2323
@NSManaged public var currency: String?
24-
24+
@NSManaged public var orderInfo: BookingOrderInfo?
2525
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
import CoreData
3+
4+
@objc(BookingCustomerInfo)
5+
public class BookingCustomerInfo: NSManagedObject {
6+
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Foundation
2+
import CoreData
3+
4+
extension BookingCustomerInfo {
5+
@NSManaged public var billingAddress1: String?
6+
@NSManaged public var billingAddress2: String?
7+
@NSManaged public var billingCity: String?
8+
@NSManaged public var billingCompany: String?
9+
@NSManaged public var billingCountry: String?
10+
@NSManaged public var billingEmail: String?
11+
@NSManaged public var billingFirstName: String?
12+
@NSManaged public var billingLastName: String?
13+
@NSManaged public var billingPhone: String?
14+
@NSManaged public var billingPostcode: String?
15+
@NSManaged public var billingState: String?
16+
@NSManaged public var orderInfo: BookingOrderInfo?
17+
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
import CoreData
3+
4+
@objc(BookingOrderInfo)
5+
public class BookingOrderInfo: NSManagedObject {
6+
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Foundation
2+
import CoreData
3+
4+
extension BookingOrderInfo {
5+
@NSManaged public var statusKey: String?
6+
@NSManaged public var paymentInfo: BookingPaymentInfo?
7+
@NSManaged public var customerInfo: BookingCustomerInfo?
8+
@NSManaged public var productInfo: BookingProductInfo?
9+
@NSManaged public var booking: Booking?
10+
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
import CoreData
3+
4+
@objc(BookingPaymentInfo)
5+
public class BookingPaymentInfo: NSManagedObject {
6+
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Foundation
2+
import CoreData
3+
4+
extension BookingPaymentInfo {
5+
@NSManaged public var paymentMethodID: String?
6+
@NSManaged public var paymentMethodTitle: String?
7+
@NSManaged public var subtotal: String?
8+
@NSManaged public var subtotalTax: String?
9+
@NSManaged public var total: String?
10+
@NSManaged public var totalTax: String?
11+
@NSManaged public var orderInfo: BookingOrderInfo?
12+
}

0 commit comments

Comments
 (0)