diff LazyBear/Views/Company/Networking/Company.swift @ 438:7f2a24a774eb

Implement CompanyView networking
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sun, 20 Jun 2021 13:20:19 +0200
parents
children 01fa77358b82
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Company/Networking/Company.swift	Sun Jun 20 13:20:19 2021 +0200
@@ -0,0 +1,30 @@
+//
+//  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 data = CompanyResponse()
+    
+    func request(_ url: String, _ requestType: RequestType) {
+        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
+        }
+    }
+}