Skip to content

Commit ed0f001

Browse files
committed
implemented handing imagery list from Workspaces
- removed API calling for imagery and removed MapRepository - Added Authorization to each API request - updated imagery URL supports to {zoom} field
1 parent 089f7ae commit ed0f001

File tree

12 files changed

+40
-158
lines changed

12 files changed

+40
-158
lines changed

GoInfoGame/GoInfoGame.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@
149149
C71EB5B72E2100E30009E610 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C71EB5B22E2100E30009E610 /* NetworkManager.swift */; };
150150
C71EB5B82E2100E30009E610 /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C71EB5B32E2100E30009E610 /* NetworkMonitor.swift */; };
151151
C71EB5B92E2100E30009E610 /* APIManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C71EB5B12E2100E30009E610 /* APIManager.swift */; };
152-
C71EB5BD2E2113500009E610 /* WMTSLayers.json in Resources */ = {isa = PBXBuildFile; fileRef = C71EB5BC2E2113500009E610 /* WMTSLayers.json */; };
153152
C75666D02E0D068900D36C41 /* OHHTTPStubs in Frameworks */ = {isa = PBXBuildFile; productRef = C75666CF2E0D068900D36C41 /* OHHTTPStubs */; };
154153
C75666D22E0D068900D36C41 /* OHHTTPStubsSwift in Frameworks */ = {isa = PBXBuildFile; productRef = C75666D12E0D068900D36C41 /* OHHTTPStubsSwift */; };
155154
C75CC5D92E0D22F4008A94A0 /* LongQuestsResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = C75CC5D82E0D22F4008A94A0 /* LongQuestsResponse.json */; };
@@ -505,7 +504,6 @@
505504
C71EB5B22E2100E30009E610 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
506505
C71EB5B32E2100E30009E610 /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = "<group>"; };
507506
C71EB5B42E2100E30009E610 /* ResponseHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseHandler.swift; sourceTree = "<group>"; };
508-
C71EB5BC2E2113500009E610 /* WMTSLayers.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = WMTSLayers.json; sourceTree = "<group>"; };
509507
C75CC5D62E0D22F4008A94A0 /* Workspaces response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "Workspaces response.json"; sourceTree = "<group>"; };
510508
C75CC5D72E0D22F4008A94A0 /* SCLIO Seattle pins response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "SCLIO Seattle pins response.json"; sourceTree = "<group>"; };
511509
C75CC5D82E0D22F4008A94A0 /* LongQuestsResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = LongQuestsResponse.json; sourceTree = "<group>"; };
@@ -1335,7 +1333,6 @@
13351333
C75CC5D52E0D22E0008A94A0 /* SampleResponses */ = {
13361334
isa = PBXGroup;
13371335
children = (
1338-
C71EB5BC2E2113500009E610 /* WMTSLayers.json */,
13391336
C75CC5D62E0D22F4008A94A0 /* Workspaces response.json */,
13401337
C75CC5D72E0D22F4008A94A0 /* SCLIO Seattle pins response.json */,
13411338
C75CC5D82E0D22F4008A94A0 /* LongQuestsResponse.json */,
@@ -1978,7 +1975,6 @@
19781975
C76B63742E46019D0076A540 /* proximanova_regular.otf in Resources */,
19791976
C76B63752E46019D0076A540 /* proximanova_light.otf in Resources */,
19801977
C76B63762E46019D0076A540 /* proximanova_semibold.otf in Resources */,
1981-
C71EB5BD2E2113500009E610 /* WMTSLayers.json in Resources */,
19821978
C7A922252E45C36D00705E21 /* PrivacyInfo.xcprivacy in Resources */,
19831979
FAD5C4FC2AFCBE720040C61A /* Assets.xcassets in Resources */,
19841980
FAD5C4FA2AFCBE700040C61A /* Main.storyboard in Resources */,

GoInfoGame/GoInfoGame/Helpers/Extensions.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,11 @@ extension Double {
207207
(self * 1_000_0000).rounded() / 1_000_0000
208208
}
209209
}
210+
211+
extension URLRequest {
212+
mutating func addAuthorizationHeader() {
213+
if let jwtAccessToken = KeychainManager.load(key: KeychainManager.Keys.accessToken.rawValue) {
214+
self.setValue("Bearer \(jwtAccessToken)", forHTTPHeaderField: "Authorization")
215+
}
216+
}
217+
}

GoInfoGame/GoInfoGame/Helpers/SampleResponses/WMTSLayers.json

Lines changed: 0 additions & 102 deletions
This file was deleted.

GoInfoGame/GoInfoGame/Network/APIHandler/APIManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension APIRequest {
2121
var request: URLRequest = urlRequest
2222
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
2323
if let jwtAccessToken = KeychainManager.load(key: KeychainManager.Keys.accessToken.rawValue) {
24-
request.setValue(jwtAccessToken, forHTTPHeaderField: "Authorization")
24+
request.setValue("Bearer \(jwtAccessToken)", forHTTPHeaderField: "Authorization")
2525
}
2626
return request
2727
}

GoInfoGame/GoInfoGame/Network/ApiManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class ApiManager {
119119
}
120120
debugPrint("set body prepared \(Date())")
121121

122+
request.addAuthorizationHeader()
122123
if let headers = endpoint.headers {
123124
for (key, value) in headers {
124125
request.setValue(value, forHTTPHeaderField: key)

GoInfoGame/GoInfoGame/Network/models/WorkspacesResponse.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ struct Workspace: Codable,Hashable {
2727
let title: String
2828
let type: String?
2929
let externalAppAccess: Int
30+
let imageryList: SatelliteServers?
3031

3132
init(from decoder: Decoder) throws {
32-
let container = try decoder.container(keyedBy: CodingKeys.self)
33-
id = try container.decode(Int.self, forKey: .id)
34-
title = try container.decode(String.self, forKey: .title)
35-
type = try container.decodeIfPresent(String.self, forKey: .type) ?? "osw"
33+
let container = try decoder.container(keyedBy: CodingKeys.self)
34+
id = try container.decode(Int.self, forKey: .id)
35+
title = try container.decode(String.self, forKey: .title)
36+
type = try container.decodeIfPresent(String.self, forKey: .type) ?? "osw"
3637
externalAppAccess = try container.decode(Int.self, forKey: .externalAppAccess)
37-
}
38+
imageryList = try container.decodeIfPresent(SatelliteServers.self, forKey: .imageryList)
39+
}
3840

39-
enum CodingKeys: String, CodingKey {
40-
case id, title, type, externalAppAccess
41-
}
41+
enum CodingKeys: String, CodingKey {
42+
case id, title, type, externalAppAccess, imageryList
43+
}
4244
}
4345

4446
// MARK: - Polygon

GoInfoGame/GoInfoGame/UI/InitialView/InitialView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct InitialView: View {
5656
}
5757
.navigationDestination(isPresented: $shouldNavigateToMapView) {
5858
if let workspace = selectedWorkspace {
59-
MapView(selectedWorkspace: workspace)
59+
MapView(selectedWorkspace: workspace, viewModel: MapViewModel(workspace: workspace))
6060
.navigationBarBackButtonHidden(true)
6161
}
6262
}

GoInfoGame/GoInfoGame/UI/Map/MapRepository.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,3 @@ enum SatelliteOption: Identifiable, Hashable {
3434
hasher.combine(id)
3535
}
3636
}
37-
38-
protocol MapRepositoryProtocol {
39-
func fetchAvailableServers() async throws -> SatelliteServers
40-
}
41-
42-
class MapRepository: MapRepositoryProtocol {
43-
let netowrkClient: NetworkHandler
44-
init(netowrkClient: NetworkHandler = NetworkManager()) {
45-
self.netowrkClient = netowrkClient
46-
}
47-
48-
func fetchAvailableServers() async throws -> SatelliteServers {
49-
return try await netowrkClient.fetchData(request: GetWMTSLayersReqeust())
50-
}
51-
}
52-
53-
struct GetWMTSLayersReqeust: APIRequest {
54-
var urlRequest: URLRequest? {
55-
guard let url = Bundle.main.url(forResource: "WMTSLayers", withExtension: "json") else {
56-
return nil
57-
}
58-
59-
var urlRequest = URLRequest(url: url)
60-
urlRequest.httpMethod = "GET"
61-
return urlRequest
62-
}
63-
}

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import MapKit
1010
import Combine
1111

1212
struct MapView: View {
13-
let selectedWorkspace: Workspace?
13+
let selectedWorkspace: Workspace
1414
@State var trackingMode: MapUserTrackingMode = MapUserTrackingMode.follow
1515
@Environment(\.presentationMode) private var presentationMode
1616
@AppStorage("isMapFromOnboarding") var isMapFromOnboarding: Bool = false
17-
@StateObject private var viewModel = MapViewModel()
17+
@StateObject var viewModel: MapViewModel
1818
@State private var isPresented = false
1919

2020
@State private var shouldShowPolyline = true
@@ -247,7 +247,7 @@ struct MapView: View {
247247
.font(FontFamily.Lato.regular.swiftUIFont(size: 12))
248248
.foregroundStyle(Asset.Colors._83879BTextFiledTitle.swiftUIColor)
249249

250-
Text(selectedWorkspace?.title ?? "")
250+
Text(selectedWorkspace.title)
251251
.font(FontFamily.Lato.bold.swiftUIFont(size: 14))
252252
.foregroundStyle(Asset.Colors.huskyPurple.swiftUIColor)
253253
}
@@ -342,7 +342,7 @@ struct MapView: View {
342342
.presentationDragIndicator(.visible)
343343
}
344344
.sheet(isPresented: $showUserSettingsSheet) {
345-
UserSettingsView(selectedWorkspace: selectedWorkspace?.title ?? "", options: OptionModel.options, onNavigate: { navigate in
345+
UserSettingsView(selectedWorkspace: selectedWorkspace.title, options: OptionModel.options, onNavigate: { navigate in
346346
showUserSettingsSheet = false
347347
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
348348
// navigateToProfileSettings = true
@@ -506,7 +506,7 @@ struct MapView: View {
506506
})
507507
.onAppear(){
508508
HiddenQuestManager.shared.loadHiddenQuests()
509-
print("selected workspace",selectedWorkspace?.title ?? "")
509+
print("selected workspace",selectedWorkspace.title)
510510
QuestsRepository.shared.loadLongQuests(from: "longQuestJson")
511511
// self.baseUrl = "https://osm.workspaces-stage.sidewalks.washington.edu"
512512
// let original = DatabaseConnector.shared.getNode(id: 43)

GoInfoGame/GoInfoGame/UI/Map/MapViewModel.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ class MapViewModel: ObservableObject {
3535
var isMultiSelectModeEnabled = false
3636

3737
private let dbInstance = DatabaseConnector.shared
38-
let mapRepo: MapRepositoryProtocol
3938
private var allSattileLayers: [SatelliteServer] = []
4039

4140
@Published var availableOptions: [SatelliteOption] = []
4241
@Published var selectedOption: SatelliteOption = .none
4342
@Published var showSatellitePicker: Bool = false
4443
@Published private(set) var syncFailedElementsCount: Int = 0
45-
46-
init(mapRepo: MapRepositoryProtocol = MapRepository()) {
47-
self.mapRepo = mapRepo
44+
let workspace: Workspace
45+
init(workspace: Workspace) {
46+
self.workspace = workspace
4847
locationManagerDelegate.locationUpdateHandler = { [weak self] location in
4948
guard let self = self else { return }
5049

@@ -53,9 +52,7 @@ class MapViewModel: ObservableObject {
5352

5453
locationManagerDelegate.requestLocationAuthorization()
5554
locationManagerDelegate.startUpdatingLocation()
56-
Task {
57-
self.allSattileLayers = try await self.mapRepo.fetchAvailableServers()
58-
}
55+
self.allSattileLayers = workspace.imageryList ?? []
5956
checkSyncStatus()
6057
}
6158

@@ -153,6 +150,12 @@ class MapViewModel: ObservableObject {
153150
}
154151
debugPrint("response sucess: end \(Date())")
155152
case .failure(let failure):
153+
DispatchQueue.main.async { [weak self] in
154+
self?.items = []
155+
self?.isLoading = false
156+
if self?.items.count == 0 {self?.refreshMap = UUID()}
157+
}
158+
156159
print(failure)
157160
}
158161
}

0 commit comments

Comments
 (0)