Skip to content

Commit a487ca0

Browse files
committed
Connect time range parameter to StoreInfoDataService
1 parent 169d4e3 commit a487ca0

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

WooCommerce/StoreWidgets/StoreInfoDataService.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class StoreInfoDataService {
1818
///
1919
private var orderStatsRemoteV4: OrderStatsRemoteV4
2020

21-
/// Visitors remoute source
21+
/// Visitors remote source
2222
///
2323
private var siteVisitStatsRemote: SiteVisitStatsRemote
2424

@@ -32,9 +32,9 @@ final class StoreInfoDataService {
3232
siteVisitStatsRemote = SiteVisitStatsRemote(network: network)
3333
}
3434

35-
/// Async function that fetches todays stats data.
35+
/// Async function that fetches stats data for given time range.
3636
///
37-
func fetchTodayStats(for storeID: Int64) async throws -> Stats {
37+
func fetchStats(for storeID: Int64, timeRange: StatsTimeRangeV4) async throws -> Stats {
3838
// Prepare them to run in parallel
3939
async let revenueAndOrdersRequest = fetchTodaysRevenueAndOrders(for: storeID)
4040
async let visitorsRequest = fetchTodaysVisitors(for: storeID)

WooCommerce/StoreWidgets/StoreInfoProvider.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import WidgetKit
22
import WooFoundation
33
import KeychainAccess
4+
import enum Yosemite.StatsTimeRangeV4
45

56
/// Type that represents the all the possible Widget states.
67
///
@@ -90,7 +91,7 @@ final class StoreInfoProvider: IntentTimelineProvider {
9091
networkService = strongService
9192
Task {
9293
do {
93-
let todayStats = try await strongService.fetchTodayStats(for: dependencies.storeID)
94+
let todayStats = try await strongService.fetchStats(for: dependencies.storeID, timeRange: StatsTimeRangeV4(configuration.timeRange))
9495
let entry = Self.dataEntry(for: todayStats, with: dependencies)
9596
let reloadDate = Date(timeIntervalSinceNow: reloadInterval)
9697
let timeline = Timeline<StoreInfoEntry>(entries: [entry], policy: .after(reloadDate))
@@ -107,6 +108,25 @@ final class StoreInfoProvider: IntentTimelineProvider {
107108
}
108109
}
109110

111+
/// Converting StoreWidgetsConfigIntent.StatsTimeRange to StatsTimeRangeV4
112+
///
113+
private extension StatsTimeRangeV4 {
114+
init(_ timeRange: StatsTimeRange) {
115+
switch timeRange {
116+
case .today:
117+
self = .today
118+
case .thisWeek:
119+
self = .thisWeek
120+
case .thisMonth:
121+
self = .thisMonth
122+
case .thisYear:
123+
self = .thisYear
124+
default:
125+
self = .today
126+
}
127+
}
128+
}
129+
110130
private extension StoreInfoProvider {
111131

112132
/// Dependencies needed by the `StoreInfoProvider`

0 commit comments

Comments
 (0)