Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions Networking/Networking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
21DB5B99C4107CF69C0A57EC /* Pods_NetworkingTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 69314EDE650855CAF927057E /* Pods_NetworkingTests.framework */; };
6647C0161DAC6AB6570C53A7 /* Pods_Networking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F3F25DC15EC1D7C631169CB5 /* Pods_Networking.framework */; };
741B950120EBC8A700DD6E2D /* OrderCouponLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 741B950020EBC8A700DD6E2D /* OrderCouponLine.swift */; };
74C8F06420EEB44800B6EDC9 /* OrderNote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74C8F06320EEB44800B6EDC9 /* OrderNote.swift */; };
74C8F06620EEB76400B6EDC9 /* order-notes.json in Resources */ = {isa = PBXBuildFile; fileRef = 74C8F06520EEB76400B6EDC9 /* order-notes.json */; };
74C8F06820EEB7BD00B6EDC9 /* OrderNotesMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74C8F06720EEB7BC00B6EDC9 /* OrderNotesMapper.swift */; };
74C8F06A20EEBC8C00B6EDC9 /* OrderMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74C8F06920EEBC8C00B6EDC9 /* OrderMapperTests.swift */; };
74C8F06C20EEBD5D00B6EDC9 /* broken-order.json in Resources */ = {isa = PBXBuildFile; fileRef = 74C8F06B20EEBD5D00B6EDC9 /* broken-order.json */; };
74C8F06E20EEC1E800B6EDC9 /* OrderNotesMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74C8F06D20EEC1E700B6EDC9 /* OrderNotesMapperTests.swift */; };
74C8F07020EEC3A800B6EDC9 /* broken-notes.json in Resources */ = {isa = PBXBuildFile; fileRef = 74C8F06F20EEC3A800B6EDC9 /* broken-notes.json */; };
B505F6CD20BEE37E00BB1B69 /* AccountMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6CC20BEE37E00BB1B69 /* AccountMapper.swift */; };
B505F6CF20BEE38B00BB1B69 /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6CE20BEE38B00BB1B69 /* Account.swift */; };
B505F6D120BEE39600BB1B69 /* AccountRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6D020BEE39600BB1B69 /* AccountRemote.swift */; };
Expand Down Expand Up @@ -49,7 +56,7 @@
B5C6FCCF20A3592900A4F8E4 /* OrderItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6FCCE20A3592900A4F8E4 /* OrderItem.swift */; };
B5C6FCD420A373BB00A4F8E4 /* OrderMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6FCD320A373BA00A4F8E4 /* OrderMapper.swift */; };
B5C6FCD620A3768900A4F8E4 /* order.json in Resources */ = {isa = PBXBuildFile; fileRef = B5C6FCD520A3768900A4F8E4 /* order.json */; };
CE20179320E3EFA7005B4C18 /* broken-order.json in Resources */ = {isa = PBXBuildFile; fileRef = CE20179220E3EFA7005B4C18 /* broken-order.json */; };
CE20179320E3EFA7005B4C18 /* broken-orders.json in Resources */ = {isa = PBXBuildFile; fileRef = CE20179220E3EFA7005B4C18 /* broken-orders.json */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -65,6 +72,13 @@
/* Begin PBXFileReference section */
69314EDE650855CAF927057E /* Pods_NetworkingTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NetworkingTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
741B950020EBC8A700DD6E2D /* OrderCouponLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderCouponLine.swift; sourceTree = "<group>"; };
74C8F06320EEB44800B6EDC9 /* OrderNote.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderNote.swift; sourceTree = "<group>"; };
74C8F06520EEB76400B6EDC9 /* order-notes.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "order-notes.json"; sourceTree = "<group>"; };
74C8F06720EEB7BC00B6EDC9 /* OrderNotesMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderNotesMapper.swift; sourceTree = "<group>"; };
74C8F06920EEBC8C00B6EDC9 /* OrderMapperTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderMapperTests.swift; sourceTree = "<group>"; };
74C8F06B20EEBD5D00B6EDC9 /* broken-order.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "broken-order.json"; sourceTree = "<group>"; };
74C8F06D20EEC1E700B6EDC9 /* OrderNotesMapperTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderNotesMapperTests.swift; sourceTree = "<group>"; };
74C8F06F20EEC3A800B6EDC9 /* broken-notes.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "broken-notes.json"; sourceTree = "<group>"; };
753D6504FF01F09F6A33B73E /* Pods-Networking.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Networking.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Networking/Pods-Networking.debug.xcconfig"; sourceTree = "<group>"; };
B505F6CC20BEE37E00BB1B69 /* AccountMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountMapper.swift; sourceTree = "<group>"; };
B505F6CE20BEE38B00BB1B69 /* Account.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -110,7 +124,7 @@
B5C6FCD520A3768900A4F8E4 /* order.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = order.json; sourceTree = "<group>"; };
BD9439D9B8F2C1ED2EADAA51 /* Pods-NetworkingTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NetworkingTests.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-NetworkingTests/Pods-NetworkingTests.debug.xcconfig"; sourceTree = "<group>"; };
C8F9A8CC6F90A8C9B5EF2EE2 /* Pods-Networking.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Networking.release.xcconfig"; path = "../Pods/Target Support Files/Pods-Networking/Pods-Networking.release.xcconfig"; sourceTree = "<group>"; };
CE20179220E3EFA7005B4C18 /* broken-order.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "broken-order.json"; sourceTree = "<group>"; };
CE20179220E3EFA7005B4C18 /* broken-orders.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "broken-orders.json"; sourceTree = "<group>"; };
F3F25DC15EC1D7C631169CB5 /* Pods_Networking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Networking.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F6CEE1CA2AD376C0C28AE9F6 /* Pods-NetworkingTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NetworkingTests.release.xcconfig"; path = "../Pods/Target Support Files/Pods-NetworkingTests/Pods-NetworkingTests.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -279,10 +293,11 @@
children = (
B505F6CE20BEE38B00BB1B69 /* Account.swift */,
B5BB1D0F20A237FB00112D92 /* Address.swift */,
741B950020EBC8A700DD6E2D /* OrderCouponLine.swift */,
B557DA1C20979E7D005962F4 /* Order.swift */,
B5BB1D1120A255EC00112D92 /* OrderStatus.swift */,
741B950020EBC8A700DD6E2D /* OrderCouponLine.swift */,
B5C6FCCE20A3592900A4F8E4 /* OrderItem.swift */,
74C8F06320EEB44800B6EDC9 /* OrderNote.swift */,
B5BB1D1120A255EC00112D92 /* OrderStatus.swift */,
);
path = Model;
sourceTree = "<group>";
Expand All @@ -293,7 +308,10 @@
B505F6D420BEE4E600BB1B69 /* me.json */,
B559EBA920A0B5CD00836CD4 /* orders-load-all.json */,
B5C6FCD520A3768900A4F8E4 /* order.json */,
CE20179220E3EFA7005B4C18 /* broken-order.json */,
CE20179220E3EFA7005B4C18 /* broken-orders.json */,
74C8F06B20EEBD5D00B6EDC9 /* broken-order.json */,
74C8F06520EEB76400B6EDC9 /* order-notes.json */,
74C8F06F20EEC3A800B6EDC9 /* broken-notes.json */,
);
path = Responses;
sourceTree = "<group>";
Expand All @@ -305,6 +323,7 @@
B505F6CC20BEE37E00BB1B69 /* AccountMapper.swift */,
B5C6FCD320A373BA00A4F8E4 /* OrderMapper.swift */,
B567AF2A20A0FA4200AB6C62 /* OrderListMapper.swift */,
74C8F06720EEB7BC00B6EDC9 /* OrderNotesMapper.swift */,
);
path = Mapper;
sourceTree = "<group>";
Expand All @@ -330,6 +349,8 @@
children = (
B505F6D220BEE3A500BB1B69 /* AccountMapperTests.swift */,
B5C6FCCC20A34B8300A4F8E4 /* OrderListMapperTests.swift */,
74C8F06920EEBC8C00B6EDC9 /* OrderMapperTests.swift */,
74C8F06D20EEC1E700B6EDC9 /* OrderNotesMapperTests.swift */,
);
path = Mapper;
sourceTree = "<group>";
Expand Down Expand Up @@ -447,10 +468,13 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
74C8F06620EEB76400B6EDC9 /* order-notes.json in Resources */,
74C8F06C20EEBD5D00B6EDC9 /* broken-order.json in Resources */,
B505F6D520BEE4E700BB1B69 /* me.json in Resources */,
B5C6FCD620A3768900A4F8E4 /* order.json in Resources */,
B559EBAA20A0B5CD00836CD4 /* orders-load-all.json in Resources */,
CE20179320E3EFA7005B4C18 /* broken-order.json in Resources */,
CE20179320E3EFA7005B4C18 /* broken-orders.json in Resources */,
74C8F07020EEC3A800B6EDC9 /* broken-notes.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -522,6 +546,7 @@
files = (
B557DA1A20979D66005962F4 /* Settings.swift in Sources */,
741B950120EBC8A700DD6E2D /* OrderCouponLine.swift in Sources */,
74C8F06420EEB44800B6EDC9 /* OrderNote.swift in Sources */,
B5BB1D0C20A2050300112D92 /* DateFormatter+Woo.swift in Sources */,
B567AF2520A0CCA300AB6C62 /* AuthenticatedRequest.swift in Sources */,
B505F6EA20BEFC3700BB1B69 /* MockupNetwork.swift in Sources */,
Expand All @@ -537,6 +562,7 @@
B5C6FCCF20A3592900A4F8E4 /* OrderItem.swift in Sources */,
B505F6EC20BEFDC200BB1B69 /* Loader.swift in Sources */,
B5BB1D1220A255EC00112D92 /* OrderStatus.swift in Sources */,
74C8F06820EEB7BD00B6EDC9 /* OrderNotesMapper.swift in Sources */,
B5BB1D1020A237FB00112D92 /* Address.swift in Sources */,
B557DA0420975500005962F4 /* OrdersRemote.swift in Sources */,
B5C6FCD420A373BB00A4F8E4 /* OrderMapper.swift in Sources */,
Expand All @@ -554,10 +580,12 @@
files = (
B505F6D320BEE3A500BB1B69 /* AccountMapperTests.swift in Sources */,
B5C6FCC820A32E4800A4F8E4 /* DateFormatterWooTests.swift in Sources */,
74C8F06A20EEBC8C00B6EDC9 /* OrderMapperTests.swift in Sources */,
B567AF3120A0FB8F00AB6C62 /* JetpackRequestTests.swift in Sources */,
B505F6D720BEE58800BB1B69 /* AccountRemoteTests.swift in Sources */,
B518662A20A09C6F00037A38 /* OrdersRemoteTests.swift in Sources */,
B5969E1520A47F99005E9DF1 /* RemoteTests.swift in Sources */,
74C8F06E20EEC1E800B6EDC9 /* OrderNotesMapperTests.swift in Sources */,
B567AF2F20A0FB8F00AB6C62 /* AuthenticatedRequestTests.swift in Sources */,
B5C6FCCD20A34B8300A4F8E4 /* OrderListMapperTests.swift in Sources */,
B518663520A0A2E800037A38 /* Constants.swift in Sources */,
Expand Down
29 changes: 29 additions & 0 deletions Networking/Networking/Mapper/OrderNotesMapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Foundation


/// Mapper: OrderNotes
///
class OrderNotesMapper: Mapper {

/// (Attempts) to convert a dictionary into [OrderNote].
///
func map(response: Data) throws -> [OrderNote] {
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(DateFormatter.Defaults.dateTimeFormatter)

return try decoder.decode(OrderNotesEnvelope.self, from: response).orderNotes
}
}


/// OrderNote Disposable Entity:
/// `Load Order Notes` endpoint returns all of its notes within the `data` key. This entity
/// allows us to do parse all the things with JSONDecoder.
///
private struct OrderNotesEnvelope: Decodable {
let orderNotes: [OrderNote]

private enum CodingKeys: String, CodingKey {
case orderNotes = "data"
}
}
63 changes: 63 additions & 0 deletions Networking/Networking/Model/OrderNote.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import Foundation


/// Represents an Order's Note Entity.
///
public struct OrderNote: Decodable {
public let noteId: Int
public let dateCreated: Date
public let note: String
public let isCustomerNote: Bool

/// Order struct initializer.
///
init(noteId: Int, dateCreated: Date, note: String, isCustomerNote: Bool) {
self.noteId = noteId
self.dateCreated = dateCreated
self.note = note
self.isCustomerNote = isCustomerNote
}

/// The public initializer for OrderNote.
///
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let noteId = try container.decode(Int.self, forKey: .noteId)
let dateCreated = try container.decodeIfPresent(Date.self, forKey: .dateCreated) ?? Date()
let note = try container.decode(String.self, forKey: .note)
let isCustomerNote = try container.decode(Bool.self, forKey: .isCustomerNote)

self.init(noteId: noteId, dateCreated: dateCreated, note: note, isCustomerNote: isCustomerNote) // initialize the struct
}
}


/// Defines all of the OrderNote's CodingKeys.
///
private extension OrderNote {

enum CodingKeys: String, CodingKey {
case noteId = "id"
case dateCreated = "date_created_gmt"
case note = "note"
case isCustomerNote = "customer_note"
}
}


// MARK: - Comparable Conformance
//
extension OrderNote: Comparable {
public static func == (lhs: OrderNote, rhs: OrderNote) -> Bool {
return lhs.noteId == rhs.noteId &&
lhs.dateCreated == rhs.dateCreated &&
lhs.note == rhs.note &&
lhs.isCustomerNote == rhs.isCustomerNote
}

public static func < (lhs: OrderNote, rhs: OrderNote) -> Bool {
return lhs.noteId < rhs.noteId ||
(lhs.noteId == rhs.noteId && lhs.dateCreated < rhs.dateCreated) ||
(lhs.noteId == rhs.noteId && lhs.dateCreated == rhs.dateCreated && lhs.note < rhs.note)
}
}
24 changes: 20 additions & 4 deletions Networking/Networking/Remote/OrdersRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class OrdersRemote: Remote {
/// Retrieves a specific `Order`
///
/// - Parameters:
/// - siteID: Site for which we'll fetch remote orders.
/// - orderID: Order for which we'll fetch remote orders.
/// - siteID: Site which hosts the Order.
/// - orderID: Identifier of the Order.
/// - completion: Closure to be executed upon completion.
///
public func loadOrder(for siteID: Int, orderID: Int, completion: @escaping (Order?, Error?) -> Void) {
Expand All @@ -37,6 +37,21 @@ public class OrdersRemote: Remote {
enqueue(request, mapper: mapper, completion: completion)
}

/// Retrieves the notes for a specific `Order`
///
/// - Parameters:
/// - siteID: Site which hosts the Order.
/// - orderID: Identifier of the Order.
/// - completion: Closure to be executed upon completion.
///
public func loadOrderNotes(for siteID: Int, orderID: Int, completion: @escaping ([OrderNote]?, Error?) -> Void) {
let path = "\(Constants.ordersPath)/\(orderID)/\(Constants.notesPath)/"
let request = JetpackRequest(wooApiVersion: .mark2, method: .get, siteID: siteID, path: path, parameters: nil)
let mapper = OrderNotesMapper()

enqueue(request, mapper: mapper, completion: completion)
}

/// Updates the `OrderStatus` of a given Order.
///
/// - Parameters:
Expand All @@ -60,8 +75,9 @@ public class OrdersRemote: Remote {
//
private extension OrdersRemote {
enum Constants {
static let defaultPageSize: Int = 75
static let ordersPath: String = "orders"
static let defaultPageSize: Int = 75
static let ordersPath: String = "orders"
static let notesPath: String = "notes"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAY ALIGNMENT!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always! 🤣

}

enum ParameterKeys {
Expand Down
4 changes: 2 additions & 2 deletions Networking/NetworkingTests/Mapper/OrderListMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class OrderListMapperTests: XCTestCase {
let brokenOrder = orders[0]
let format = DateFormatter()
format.dateStyle = .short

let orderCreatedString = format.string(from: brokenOrder.dateCreated)
let todayCreatedString = format.string(from: Date())
XCTAssertEqual(orderCreatedString, todayCreatedString)
Expand Down Expand Up @@ -120,6 +120,6 @@ private extension OrderListMapperTests {
/// Returns the OrderlistMapper output upon receiving `broken-order`
///
func mapLoadBrokenOrderResponse() -> [Order] {
return mapOrders(from: "broken-order")
return mapOrders(from: "broken-orders")
}
}
Loading