|
8 | 8 |
|
9 | 9 | import Foundation |
10 | 10 |
|
11 | | -struct DiningMenuAPIResponse: Codable { |
| 11 | +struct MenuList: Codable { |
12 | 12 | static let directory = "diningMenus.json" |
13 | 13 |
|
14 | | - let document: Document |
15 | | - |
16 | | - enum CodingKeys: String, CodingKey { |
17 | | - case document = "Document" |
18 | | - } |
19 | | - |
20 | | - struct Document: Codable { |
21 | | - let dateString: String |
22 | | - let menuDocument: MenuDocument |
23 | | - |
24 | | - enum CodingKeys: String, CodingKey { |
25 | | - case dateString = "menudate" |
26 | | - case menuDocument = "tblMenu" |
27 | | - } |
28 | | - } |
29 | | -} |
30 | | - |
31 | | -struct MenuDocument: Codable { |
32 | 14 | let menus: [DiningMenu] |
33 | | - |
34 | | - enum CodingKeys: String, CodingKey { |
35 | | - case menus = "tblDayPart" |
36 | | - } |
37 | 15 | } |
38 | 16 |
|
39 | 17 | struct DiningMenu: Codable, Hashable { |
40 | | - |
41 | | - let mealType: String |
42 | | - let diningStations: [DiningStation] |
| 18 | + let venueInfo: VenueInfo |
| 19 | + let date: Date |
| 20 | + let startTime: String |
| 21 | + let endTime: String |
| 22 | + let stations: [DiningStation] |
| 23 | + let service: String |
43 | 24 |
|
44 | 25 | enum CodingKeys: String, CodingKey { |
45 | | - case mealType = "txtDayPartDescription" |
46 | | - case diningStations = "tblStation" |
| 26 | + case venueInfo = "venue" |
| 27 | + case date |
| 28 | + case startTime = "start_time" |
| 29 | + case endTime = "end_time" |
| 30 | + case stations |
| 31 | + case service |
47 | 32 | } |
48 | 33 | } |
49 | 34 |
|
50 | | -struct DiningStation: Codable, Hashable { |
51 | | - let stationDescription: String |
52 | | - let diningStationItems: [DiningStationItem] |
53 | | - |
| 35 | +struct VenueInfo: Codable, Hashable { |
| 36 | + let id: Int |
| 37 | + let name: String |
| 38 | + let image: String |
| 39 | + |
54 | 40 | enum CodingKeys: String, CodingKey { |
55 | | - case stationDescription = "txtStationDescription" |
56 | | - case diningStationItems = "tblItem" |
| 41 | + case id = "venue_id" |
| 42 | + case name |
| 43 | + case image = "image_url" |
57 | 44 | } |
58 | 45 | } |
59 | 46 |
|
60 | | -struct DiningStationItem: Codable, Hashable { |
61 | | - |
62 | | - let tableAttribute: Attribute |
63 | | - let title: String |
64 | | - let description: String |
| 47 | +struct DiningStation: Codable, Hashable { |
| 48 | + let name: String |
| 49 | + let items: [DiningStationItem] |
65 | 50 |
|
66 | 51 | enum CodingKeys: String, CodingKey { |
67 | | - case tableAttribute = "tblAttributes" |
68 | | - case title = "txtTitle" |
69 | | - case description = "txtDescription" |
70 | | - } |
71 | | - |
72 | | - init(from decoder: Decoder) throws { |
73 | | - let container = try decoder.container(keyedBy: CodingKeys.self) |
74 | | - |
75 | | - if let data = try? container.decode(Attribute.self, forKey: .tableAttribute) { |
76 | | - self.tableAttribute = data |
77 | | - } else { |
78 | | - self.tableAttribute = Attribute() |
79 | | - } |
80 | | - |
81 | | -// self.tblFarmToFork = try! container.decode(String.self, forKey: .tblFarmToFork) |
82 | | - self.title = try container.decode(String.self, forKey: .title) |
83 | | - self.description = try container.decode(String.self, forKey: .description) |
| 52 | + case name |
| 53 | + case items |
84 | 54 | } |
85 | 55 | } |
86 | 56 |
|
87 | | -struct Attribute: Codable, Hashable { |
88 | | - init() { |
89 | | - attributeDescriptions = [] |
90 | | - } |
91 | | - |
92 | | - let attributeDescriptions: [AttributeDescription] |
| 57 | +struct DiningStationItem: Codable, Hashable { |
| 58 | + let id: Int |
| 59 | + let name: String |
| 60 | + let desc: String |
| 61 | + let ingredients: String |
93 | 62 |
|
94 | 63 | enum CodingKeys: String, CodingKey { |
95 | | - case attributeDescriptions = "txtAttribute" |
| 64 | + case id = "item_id" |
| 65 | + case name |
| 66 | + case desc = "description" |
| 67 | + case ingredients |
96 | 68 | } |
97 | | - |
98 | | - init(from decoder: Decoder) throws { |
99 | | - let container = try decoder.container(keyedBy: CodingKeys.self) |
100 | | - |
101 | | - if let data = try? container.decode(AttributeDescription.self, forKey: .attributeDescriptions) { |
102 | | - self.attributeDescriptions = [data] |
103 | | - } else { |
104 | | - let data = try container.decode([AttributeDescription].self, forKey: .attributeDescriptions) |
105 | | - self.attributeDescriptions = data |
106 | | - } |
107 | | - } |
108 | | -} |
109 | | - |
110 | | -struct AttributeDescription: Codable, Hashable { |
111 | | - let description: String |
112 | 69 | } |
0 commit comments