File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Networking/Networking/Mapper Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments