Skip to content

Commit

Permalink
Update fetchSystemStatusReport remote and action to use `SystemStat…
Browse files Browse the repository at this point in the history
…usReport` type for SSR.
  • Loading branch information
jaclync committed Jan 2, 2025
1 parent 3e3bdd0 commit 150b837
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Networking/Networking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
028FA473257E110700F88A48 /* shipping-label-refund-error.json in Resources */ = {isa = PBXBuildFile; fileRef = 028FA471257E110700F88A48 /* shipping-label-refund-error.json */; };
028FA474257E110700F88A48 /* shipping-label-refund-success.json in Resources */ = {isa = PBXBuildFile; fileRef = 028FA472257E110700F88A48 /* shipping-label-refund-success.json */; };
0291496E2D2634F800F7B3B3 /* SystemStatusReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0291496D2D2634F800F7B3B3 /* SystemStatusReport.swift */; };
029149702D263AE700F7B3B3 /* SystemStatusReportMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0291496F2D263AE700F7B3B3 /* SystemStatusReportMapper.swift */; };
02935AEE29DFFA74001B793E /* site-enable-trial-success.json in Resources */ = {isa = PBXBuildFile; fileRef = 02935AEC29DFFA74001B793E /* site-enable-trial-success.json */; };
02935AEF29DFFA74001B793E /* site-enable-trial-error-already-upgraded.json in Resources */ = {isa = PBXBuildFile; fileRef = 02935AED29DFFA74001B793E /* site-enable-trial-error-already-upgraded.json */; };
029B86902A6FBBE000E944D1 /* wcpay-account-null-isLive.json in Resources */ = {isa = PBXBuildFile; fileRef = 029B868F2A6FBBE000E944D1 /* wcpay-account-null-isLive.json */; };
Expand Down Expand Up @@ -1368,6 +1369,7 @@
028FA471257E110700F88A48 /* shipping-label-refund-error.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-refund-error.json"; sourceTree = "<group>"; };
028FA472257E110700F88A48 /* shipping-label-refund-success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-refund-success.json"; sourceTree = "<group>"; };
0291496D2D2634F800F7B3B3 /* SystemStatusReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemStatusReport.swift; sourceTree = "<group>"; };
0291496F2D263AE700F7B3B3 /* SystemStatusReportMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemStatusReportMapper.swift; sourceTree = "<group>"; };
02935AEC29DFFA74001B793E /* site-enable-trial-success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "site-enable-trial-success.json"; sourceTree = "<group>"; };
02935AED29DFFA74001B793E /* site-enable-trial-error-already-upgraded.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "site-enable-trial-error-already-upgraded.json"; sourceTree = "<group>"; };
029B868F2A6FBBE000E944D1 /* wcpay-account-null-isLive.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "wcpay-account-null-isLive.json"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3060,6 +3062,7 @@
CC75108A29EFF1A90035FBA4 /* SubscriptionStatus.swift */,
077F39C7269F2C7E00ABEADC /* SystemPlugin.swift */,
3148976F27232982007A86BD /* SystemStatus.swift */,
0291496D2D2634F800F7B3B3 /* SystemStatusReport.swift */,
DEC51AE527684717009F3DF4 /* SystemStatusDetails */,
450106842399A7CB00E24722 /* TaxClass.swift */,
31799AF7270508C600D78179 /* RemoteReaderLocation.swift */,
Expand Down Expand Up @@ -3089,7 +3092,6 @@
EE078D8E2AD2E65400C1199E /* JWToken.swift */,
DEDA8DA02B182E850076BF0F /* WordPressTheme.swift */,
DE78DE452B2AE880002E58DE /* WordPressPage.swift */,
0291496D2D2634F800F7B3B3 /* SystemStatusReport.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -3668,6 +3670,7 @@
CE606D8E2BE39426001CB424 /* ShippingMethodMapper.swift */,
FE28F6E326842848004465C7 /* UserMapper.swift */,
077F39D326A58DE700ABEADC /* SystemStatusMapper.swift */,
0291496F2D263AE700F7B3B3 /* SystemStatusReportMapper.swift */,
DEC51AE827687AAF009F3DF4 /* SystemPluginMapper.swift */,
02C11275274285FF00F4F0B4 /* WooCommerceAvailabilityMapper.swift */,
02BE0A7A274B695F001176D2 /* WordPressMediaMapper.swift */,
Expand Down Expand Up @@ -5068,6 +5071,7 @@
0359EA0F27AAC6410048DE2D /* WCPayPaymentMethodDetails.swift in Sources */,
7426CA1121AF30BD004E9FFC /* SiteAPIMapper.swift in Sources */,
57E8FED3246616AC0057CD68 /* Result+Extensions.swift in Sources */,
029149702D263AE700F7B3B3 /* SystemStatusReportMapper.swift in Sources */,
020D07BC23D856BF00FD9580 /* MediaRemote.swift in Sources */,
CE71E2312A4C3DDA00DB5376 /* ProductsReportMapper.swift in Sources */,
0286981429ED2D6400853B88 /* GenerativeContentRemote.swift in Sources */,
Expand Down
37 changes: 37 additions & 0 deletions Networking/Networking/Mapper/SystemStatusReportMapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Foundation

/// Mapper: System Status Report
///
struct SystemStatusReportMapper: Mapper {

/// Site Identifier associated to the system status that will be parsed.
/// We're injecting this field via `JSONDecoder.userInfo` because the remote endpoints don't return the SiteID in the system plugin endpoint.
///
let siteID: Int64

/// (Attempts) to convert a dictionary into SystemStatusReport
///
func map(response: Data) throws -> SystemStatusReport {
let decoder = JSONDecoder()
decoder.userInfo = [
.siteID: siteID
]

if hasDataEnvelope(in: response) {
return try decoder.decode(SystemStatusReportEnvelope.self, from: response).systemStatusReport
} else {
return try decoder.decode(SystemStatusReport.self, from: response)
}
}
}

/// System Status Report endpoint returns the requested account in the `data` key. This entity
/// allows us to parse it with JSONDecoder.
///
struct SystemStatusReportEnvelope: Decodable {
let systemStatusReport: SystemStatusReport

private enum CodingKeys: String, CodingKey {
case systemStatusReport = "data"
}
}
4 changes: 2 additions & 2 deletions Networking/Networking/Remote/SystemStatusRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public class SystemStatusRemote: Remote {
/// - completion: Closure to be excuted upon completion
///
public func fetchSystemStatusReport(for siteID: Int64,
completion: @escaping (Result<SystemStatus, Error>) -> Void) {
completion: @escaping (Result<SystemStatusReport, Error>) -> Void) {
let path = Constants.systemStatusPath
let request = JetpackRequest(wooApiVersion: .mark3,
method: .get,
siteID: siteID,
path: path,
parameters: nil,
availableAsRESTRequest: true)
let mapper = SystemStatusMapper(siteID: siteID)
let mapper = SystemStatusReportMapper(siteID: siteID)
enqueue(request, mapper: mapper, completion: completion)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private extension SystemStatusReportViewModel {
/// Format system status to match with Core's report.
/// Not localizing content and keep English by default.
///
func formatReport(with systemStatus: SystemStatus) -> String {
func formatReport(with systemStatus: SystemStatusReport) -> String {
var lines = ["### System Status Report generated via the WooCommerce iOS app ###"]

// Environment
Expand Down
2 changes: 1 addition & 1 deletion Yosemite/Yosemite/Actions/SystemStatusAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public enum SystemStatusAction: Action {

/// Fetch system status report for a site given its ID
///
case fetchSystemStatusReport(siteID: Int64, onCompletion: (Result<SystemStatus, Error>) -> Void)
case fetchSystemStatusReport(siteID: Int64, onCompletion: (Result<SystemStatusReport, Error>) -> Void)
}
1 change: 1 addition & 0 deletions Yosemite/Yosemite/Model/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public typealias SubscriptionPeriod = Networking.SubscriptionPeriod
public typealias SubscriptionStatus = Networking.SubscriptionStatus
public typealias SystemPlugin = Networking.SystemPlugin
public typealias SystemStatus = Networking.SystemStatus
public typealias SystemStatusReport = Networking.SystemStatusReport
public typealias TaxClass = Networking.TaxClass
public typealias TaxRate = Networking.TaxRate
public typealias TopEarnerStats = Networking.TopEarnerStats
Expand Down
2 changes: 1 addition & 1 deletion Yosemite/Yosemite/Stores/SystemStatusStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private extension SystemStatusStore {
}
}

func fetchSystemStatusReport(siteID: Int64, completionHandler: @escaping (Result<SystemStatus, Error>) -> Void) {
func fetchSystemStatusReport(siteID: Int64, completionHandler: @escaping (Result<SystemStatusReport, Error>) -> Void) {
remote.fetchSystemStatusReport(for: siteID, completion: completionHandler)
}
}
Expand Down

0 comments on commit 150b837

Please sign in to comment.