Mercurial > public > lazybear
comparison LazyBear/Views/Home/TradingDates.swift @ 346:80bfa88c6b0f
Implementing Prop API
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sun, 11 Apr 2021 19:55:47 +0200 |
parents | e81c18164afb |
children | 5ccceb527178 |
comparison
equal
deleted
inserted
replaced
345:fde2b30c719e | 346:80bfa88c6b0f |
---|---|
5 // Created by Dennis Concepción Martín on 30/3/21. | 5 // Created by Dennis Concepción Martín on 30/3/21. |
6 // | 6 // |
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 enum DateType { | |
11 case holidays, trading | |
12 } | |
13 | 10 |
14 struct TradingDates: View { | 11 struct TradingDates: View { |
15 @State private var dates = [TradingDatesModel]() | 12 var dates: [TradingDatesModel] |
16 @State private var showingView = false | |
17 | |
18 private let baseUrl = Bundle.main.infoDictionary?["IEX_URL"] as? String ?? "Empty url" | |
19 private let apiKey = Bundle.main.infoDictionary?["IEX_API"] as? String ?? "Empty key" | |
20 | 13 |
21 var body: some View { | 14 var body: some View { |
22 NavigationView { | 15 NavigationView { |
23 ScrollView { | 16 ScrollView { |
24 VStack(spacing: 20) { | 17 VStack(spacing: 20) { |
26 TradingDatesItem(date: date) | 19 TradingDatesItem(date: date) |
27 } | 20 } |
28 } | 21 } |
29 .padding() | 22 .padding() |
30 } | 23 } |
31 .onAppear { requestDates(.holidays) } | |
32 .navigationTitle("Holiday dates") | 24 .navigationTitle("Holiday dates") |
33 .navigationBarTitleDisplayMode(.inline) | 25 .navigationBarTitleDisplayMode(.inline) |
34 } | |
35 } | |
36 | |
37 private func requestDates(_ dateType: DateType) { | |
38 switch dateType { | |
39 case .trading: | |
40 let tradingUrl = "\(baseUrl)/ref-data/us/dates/trade/next/10?token=\(apiKey)" | |
41 genericRequest(url: tradingUrl, model: [TradingDatesModel].self) { | |
42 self.dates = $0 | |
43 self.showingView = true | |
44 } | |
45 case.holidays: | |
46 let holidaysUrl = "\(baseUrl)/ref-data/us/dates/holiday/next/10?token=\(apiKey)" | |
47 genericRequest(url: holidaysUrl, model: [TradingDatesModel].self) { | |
48 self.dates = $0 | |
49 self.showingView = true | |
50 } | |
51 } | 26 } |
52 } | 27 } |
53 | 28 |
54 private func getArrayOfDates() -> [Date] { | 29 private func getArrayOfDates() -> [Date] { |
55 // Get array of the string dates | 30 // Get array of the string dates |
69 } | 44 } |
70 } | 45 } |
71 | 46 |
72 struct TradingDate_Previews: PreviewProvider { | 47 struct TradingDate_Previews: PreviewProvider { |
73 static var previews: some View { | 48 static var previews: some View { |
74 // Format is YYY-MM-DD | 49 // Format is YYYY-MM-DD |
75 TradingDates() | 50 TradingDates(dates: [TradingDatesModel(date: "2021-01-01")]) |
76 } | 51 } |
77 } | 52 } |