Mercurial > public > lazybear
diff 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 |
line wrap: on
line diff
--- a/LazyBear/Views/Home/TradingDates.swift Thu Apr 08 20:15:28 2021 +0200 +++ b/LazyBear/Views/Home/TradingDates.swift Sun Apr 11 19:55:47 2021 +0200 @@ -7,16 +7,9 @@ import SwiftUI -enum DateType { - case holidays, trading -} struct TradingDates: View { - @State private var dates = [TradingDatesModel]() - @State private var showingView = false - - private let baseUrl = Bundle.main.infoDictionary?["IEX_URL"] as? String ?? "Empty url" - private let apiKey = Bundle.main.infoDictionary?["IEX_API"] as? String ?? "Empty key" + var dates: [TradingDatesModel] var body: some View { NavigationView { @@ -28,29 +21,11 @@ } .padding() } - .onAppear { requestDates(.holidays) } .navigationTitle("Holiday dates") .navigationBarTitleDisplayMode(.inline) } } - private func requestDates(_ dateType: DateType) { - switch dateType { - case .trading: - let tradingUrl = "\(baseUrl)/ref-data/us/dates/trade/next/10?token=\(apiKey)" - genericRequest(url: tradingUrl, model: [TradingDatesModel].self) { - self.dates = $0 - self.showingView = true - } - case.holidays: - let holidaysUrl = "\(baseUrl)/ref-data/us/dates/holiday/next/10?token=\(apiKey)" - genericRequest(url: holidaysUrl, model: [TradingDatesModel].self) { - self.dates = $0 - self.showingView = true - } - } - } - private func getArrayOfDates() -> [Date] { // Get array of the string dates let stringDates = self.dates.map { $0.date } @@ -71,7 +46,7 @@ struct TradingDate_Previews: PreviewProvider { static var previews: some View { - // Format is YYY-MM-DD - TradingDates() + // Format is YYYY-MM-DD + TradingDates(dates: [TradingDatesModel(date: "2021-01-01")]) } }