File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff line change 11import WidgetKit
22import WooFoundation
33import 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+
110130private extension StoreInfoProvider {
111131
112132 /// Dependencies needed by the `StoreInfoProvider`
You can’t perform that action at this time.
0 commit comments