view LazyBear/Views/Company/Networking/Company.swift @ 440:01fa77358b82

Fixes #47
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sun, 20 Jun 2021 16:58:36 +0200
parents 7f2a24a774eb
children 4b8031e696e8
line wrap: on
line source

//
//  Company.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 20/6/21.
//

import SwiftUI
import Bazooka

class Company: ObservableObject {
    @Published var showView = false
    @Published var showChart = true  /// To show a ProgressView when the chart is refreshed (Date range selected)
    @Published var data = CompanyResponse()
    
    func request(_ url: String, _ requestType: RequestType) {
        if requestType == .refresh { self.showChart = false }
        let bazooka = Bazooka()
        bazooka.request(url: url, model: CompanyResponse.self) { response in
            switch requestType {
            case .initial:
                self.data = response
            case .streaming:
                self.data.quote = response.quote
            case .refresh:
                self.data.historicalPrices = response.historicalPrices
            }
            
            self.showView = true
            self.showChart = true
        }
    }
}