Skip to content

Commit f421cae

Browse files
committed
Implements SiteListMapper
1 parent b276cb5 commit f421cae

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
4+
/// Mapper: SiteList
5+
///
6+
class SiteListMapper: Mapper {
7+
8+
/// (Attempts) to convert a dictionary into [Site].
9+
///
10+
func map(response: Data) throws -> [Site] {
11+
let decoder = JSONDecoder()
12+
decoder.dateDecodingStrategy = .formatted(DateFormatter.Defaults.dateTimeFormatter)
13+
14+
return try decoder.decode(SiteListEnvelope.self, from: response).sites
15+
}
16+
}
17+
18+
19+
/// SiteList Disposable Entity:
20+
/// `Load All Sites` endpoint returns all of its orders within the `sites` key. This entity
21+
/// allows us to do parse all the things with JSONDecoder.
22+
///
23+
private struct SiteListEnvelope: Decodable {
24+
let sites: [Site]
25+
26+
private enum CodingKeys: String, CodingKey {
27+
case sites = "sites"
28+
}
29+
}

0 commit comments

Comments
 (0)