Skip to content

Commit b5dd3c7

Browse files
authored
[Woo POS] Modularization: refactor POS entry point initializer to minimize public dependencies (#16175)
2 parents 6a1c368 + a894857 commit b5dd3c7

26 files changed

+254
-418
lines changed

Modules/Sources/Yosemite/Model/Model.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public typealias FallibleCancelable = Hardware.FallibleCancelable
3131
public typealias CommentStatus = Networking.CommentStatus
3232
public typealias CompositeComponentOptionType = Networking.CompositeComponentOptionType
3333
public typealias Coupon = Networking.Coupon
34+
public typealias CouponDiscountType = Networking.Coupon.DiscountType
3435
public typealias CouponReport = Networking.CouponReport
3536
public typealias Country = Networking.Country
3637
public typealias CreateAccountResult = Networking.CreateAccountResult

Modules/Sources/Yosemite/PointOfSale/Coupons/PointOfSaleCouponFetchStrategy.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public protocol PointOfSaleCouponFetchStrategy {
88
func fetchLocalCoupons() async throws -> [POSItem]
99
}
1010

11-
public struct PointOfSaleDefaultCouponFetchStrategy: PointOfSaleCouponFetchStrategy {
11+
struct PointOfSaleDefaultCouponFetchStrategy: PointOfSaleCouponFetchStrategy {
1212
private let siteID: Int64
1313
private let currencySettings: CurrencySettings
1414
private let storage: StorageManagerType
@@ -24,7 +24,7 @@ public struct PointOfSaleDefaultCouponFetchStrategy: PointOfSaleCouponFetchStrat
2424
self.couponStoreMethods = couponStoreMethods
2525
}
2626

27-
public func fetchCoupons(pageNumber: Int) async throws -> PagedItems<POSItem> {
27+
func fetchCoupons(pageNumber: Int) async throws -> PagedItems<POSItem> {
2828
// Update local storage with data from the remote
2929
let hasMorePages = try await syncCouponsFromRemote(pageNumber: pageNumber)
3030
// Return all local coupons, including updated ones from the remote
@@ -35,7 +35,7 @@ public struct PointOfSaleDefaultCouponFetchStrategy: PointOfSaleCouponFetchStrat
3535
/// fetchLocalCoupons provides an array of coupons that are stored locally
3636
/// It does not accept any sort of pagination
3737
/// Limited to default page size to match remote results
38-
public func fetchLocalCoupons() async throws -> [POSItem] {
38+
func fetchLocalCoupons() async throws -> [POSItem] {
3939
return await fetchLocalCoupons(limit: Constants.defaultPageSize)
4040
}
4141
}
@@ -66,7 +66,7 @@ extension PointOfSaleDefaultCouponFetchStrategy {
6666

6767
// MARK: - Search Coupon Strategy
6868

69-
public struct PointOfSaleSearchCouponFetchStrategy: PointOfSaleCouponFetchStrategy {
69+
struct PointOfSaleSearchCouponFetchStrategy: PointOfSaleCouponFetchStrategy {
7070
private let siteID: Int64
7171
private let couponStoreMethods: CouponStoreMethodsProtocol
7272
private let storage: StorageManagerType
@@ -89,7 +89,7 @@ public struct PointOfSaleSearchCouponFetchStrategy: PointOfSaleCouponFetchStrate
8989
self.analytics = analytics
9090
}
9191

92-
public func fetchCoupons(pageNumber: Int) async throws -> PagedItems<POSItem> {
92+
func fetchCoupons(pageNumber: Int) async throws -> PagedItems<POSItem> {
9393
let startTime = Date()
9494
try await couponStoreMethods.searchCoupons(siteID: siteID,
9595
keyword: searchTerm,
@@ -116,7 +116,7 @@ public struct PointOfSaleSearchCouponFetchStrategy: PointOfSaleCouponFetchStrate
116116
return resultsController.fetchCoupons(predicate: predicate)
117117
}
118118

119-
public func fetchLocalCoupons() async throws -> [POSItem] {
119+
func fetchLocalCoupons() async throws -> [POSItem] {
120120
// No support for returning local search results
121121
return []
122122
}

Modules/Sources/Yosemite/PointOfSale/Coupons/PointOfSaleCouponFetchStrategyFactory.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import class Networking.AlamofireNetwork
66
import struct Combine.AnyPublisher
77
import struct NetworkingCore.JetpackSite
88

9-
public struct PointOfSaleCouponFetchStrategyFactory {
9+
public protocol PointOfSaleCouponFetchStrategyFactoryProtocol {
10+
var defaultStrategy: PointOfSaleCouponFetchStrategy { get }
11+
func searchStrategy(searchTerm: String, analytics: POSItemFetchAnalyticsTracking) -> PointOfSaleCouponFetchStrategy
12+
}
13+
14+
public struct PointOfSaleCouponFetchStrategyFactory: PointOfSaleCouponFetchStrategyFactoryProtocol {
1015
private let siteID: Int64
1116
private let currencySettings: CurrencySettings
1217
private let storage: StorageManagerType
@@ -28,14 +33,14 @@ public struct PointOfSaleCouponFetchStrategyFactory {
2833
self.couponStoreMethods = CouponStoreMethods(storageManager: storage, remote: remote)
2934
}
3035

31-
public var defaultStrategy: PointOfSaleDefaultCouponFetchStrategy {
36+
public var defaultStrategy: PointOfSaleCouponFetchStrategy {
3237
PointOfSaleDefaultCouponFetchStrategy(siteID: siteID,
3338
currencySettings: currencySettings,
3439
storage: storage,
3540
couponStoreMethods: couponStoreMethods)
3641
}
3742

38-
public func searchStrategy(searchTerm: String, analytics: POSItemFetchAnalyticsTracking) -> PointOfSaleSearchCouponFetchStrategy {
43+
public func searchStrategy(searchTerm: String, analytics: POSItemFetchAnalyticsTracking) -> PointOfSaleCouponFetchStrategy {
3944
PointOfSaleSearchCouponFetchStrategy(siteID: siteID,
4045
currencySettings: currencySettings,
4146
storage: storage,

Modules/Sources/Yosemite/PointOfSale/Items/PointOfSaleItemFetchStrategyFactory.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public protocol PointOfSaleItemFetchStrategyFactoryProtocol {
1010

1111
func searchStrategy(searchTerm: String,
1212
analytics: POSItemFetchAnalyticsTracking) -> PointOfSalePurchasableItemFetchStrategy
13-
14-
func popularStrategy(pageSize: Int) -> PointOfSalePurchasableItemFetchStrategy
1513
}
1614

1715
public final class PointOfSaleItemFetchStrategyFactory: PointOfSaleItemFetchStrategyFactoryProtocol {
@@ -69,8 +67,4 @@ public final class PointOfSaleFixedItemFetchStrategyFactory: PointOfSaleItemFetc
6967
analytics: POSItemFetchAnalyticsTracking) -> PointOfSalePurchasableItemFetchStrategy {
7068
fixedStrategy
7169
}
72-
73-
public func popularStrategy(pageSize: Int) -> PointOfSalePurchasableItemFetchStrategy {
74-
fixedStrategy
75-
}
7670
}

WooCommerce/Classes/POS/Analytics/POSCollectOrderPaymentAnalyticsTracking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
protocol POSCollectOrderPaymentAnalyticsTracking {
1+
public protocol POSCollectOrderPaymentAnalyticsTracking {
22
func trackCustomerInteractionStarted()
33
func trackOrderSyncSuccess()
44
func trackCardReaderReady()

WooCommerce/Classes/POS/Card Present Payments/CardPresentPaymentCardReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
struct CardPresentPaymentCardReader: Equatable {
3+
public struct CardPresentPaymentCardReader: Equatable {
44
let name: String
55

66
/// The reader's battery level, if available.

WooCommerce/Classes/POS/Card Present Payments/CardPresentPaymentEvent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
enum CardPresentPaymentEvent {
3+
public enum CardPresentPaymentEvent {
44
case idle
55
case show(eventDetails: CardPresentPaymentEventDetails)
66
case showOnboarding(factory: CardPresentPaymentOnboardingViewContainer, onCancel: () -> Void)

WooCommerce/Classes/POS/Card Present Payments/CardPresentPaymentEventDetails.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import struct Yosemite.CardReaderInput
33

4-
enum CardPresentPaymentEventDetails {
4+
public enum CardPresentPaymentEventDetails {
55
case scanningForReaders(endSearch: () -> Void)
66
case scanningFailed(error: Error,
77
endSearch: () -> Void)

WooCommerce/Classes/POS/Card Present Payments/CardPresentPaymentFacade.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import enum Yosemite.PaymentChannel
33
import struct Yosemite.Order
44
import Combine
55

6-
protocol CardPresentPaymentFacade {
6+
public protocol CardPresentPaymentFacade {
77
/// `paymentEventPublisher` provides a stream of events relating to a payment, including their view models,
88
/// for subscribers to display to the user. e.g. onboarding screens, connection progress, payment progress, card reader messages.
99
/// This is a long lasting stream, and will not finish during the life of the façade, instead it will publish events for each payment attempt.

WooCommerce/Classes/POS/Card Present Payments/CardPresentPaymentReaderConnectionResult.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
enum CardPresentPaymentReaderConnectionResult {
3+
public enum CardPresentPaymentReaderConnectionResult {
44
case connected(CardPresentPaymentCardReader)
55
case canceled
66
}

0 commit comments

Comments
 (0)