Skip to content

Commit a752aa4

Browse files
committed
implemented Implement aerial/satellite imagery layer logic
- added new Network manager - implemented downloading data from mock server - implemented selecting imaginary UI and updating to the map
1 parent 8cf0a87 commit a752aa4

File tree

15 files changed

+678
-29
lines changed

15 files changed

+678
-29
lines changed

GoInfoGame/GoInfoGame.xcodeproj/project.pbxproj

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,17 @@
147147
C75CC5D92E0D22F4008A94A0 /* LongQuestsResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = C75CC5D82E0D22F4008A94A0 /* LongQuestsResponse.json */; };
148148
C75CC5DA2E0D22F4008A94A0 /* Workspaces response.json in Resources */ = {isa = PBXBuildFile; fileRef = C75CC5D62E0D22F4008A94A0 /* Workspaces response.json */; };
149149
C75CC5DB2E0D22F4008A94A0 /* SCLIO Seattle pins response.json in Resources */ = {isa = PBXBuildFile; fileRef = C75CC5D72E0D22F4008A94A0 /* SCLIO Seattle pins response.json */; };
150+
C755C00E2E12BF7D002F1B30 /* SatellitePickerSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C755C00D2E12BF79002F1B30 /* SatellitePickerSheet.swift */; };
150151
C75EAD362E042D4500F75969 /* SideWalkWidth.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4E711A12B57A3B400C9DE08 /* SideWalkWidth.swift */; };
151152
C75EAD372E042D4500F75969 /* SideWalkWidthForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973FC0132B4D353800878269 /* SideWalkWidthForm.swift */; };
152153
C76187DC2E0153D800150201 /* ClusterMap in Frameworks */ = {isa = PBXBuildFile; productRef = C76187DB2E0153D800150201 /* ClusterMap */; };
154+
C7672F992E123C720084A610 /* MapRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7672F982E123A3F0084A610 /* MapRepository.swift */; };
155+
C76CAF712E1118910095E48E /* APIManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C76CAF702E11188E0095E48E /* APIManager.swift */; };
156+
C76CAF732E111A940095E48E /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C76CAF722E111A8E0095E48E /* NetworkManager.swift */; };
157+
C76CAF752E112FDF0095E48E /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C76CAF742E112FDE0095E48E /* NetworkMonitor.swift */; };
158+
C76CAF772E112FF70095E48E /* ResponseHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C76CAF762E112FF30095E48E /* ResponseHandler.swift */; };
159+
C76CAF7A2E1133060095E48E /* SatelliteServerResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = C76CAF792E1132EA0095E48E /* SatelliteServerResponse.swift */; };
160+
C76CAF7C2E11335A0095E48E /* WMTSServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C76CAF7B2E1133530095E48E /* WMTSServer.swift */; };
153161
C76DA1A12DF0679F00451E63 /* LongFormModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8C74C32C4FDE1000D28220 /* LongFormModel.swift */; };
154162
C77A4A262DF2AF3100DED8B0 /* SecureInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C77A4A252DF2AF3100DED8B0 /* SecureInputView.swift */; };
155163
C77EEBCF2DE59D3200494CB4 /* UndoMerge.swift in Sources */ = {isa = PBXBuildFile; fileRef = C77EEBCE2DE59D3200494CB4 /* UndoMerge.swift */; };
@@ -481,6 +489,14 @@
481489
C75CC5D72E0D22F4008A94A0 /* SCLIO Seattle pins response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "SCLIO Seattle pins response.json"; sourceTree = "<group>"; };
482490
C75CC5D82E0D22F4008A94A0 /* LongQuestsResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = LongQuestsResponse.json; sourceTree = "<group>"; };
483491
C75E47732E151058006D903A /* Kondapur.gpx */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Kondapur.gpx; sourceTree = "<group>"; };
492+
C755C00D2E12BF79002F1B30 /* SatellitePickerSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SatellitePickerSheet.swift; sourceTree = "<group>"; };
493+
C7672F982E123A3F0084A610 /* MapRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapRepository.swift; sourceTree = "<group>"; };
494+
C76CAF702E11188E0095E48E /* APIManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIManager.swift; sourceTree = "<group>"; };
495+
C76CAF722E111A8E0095E48E /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
496+
C76CAF742E112FDE0095E48E /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = "<group>"; };
497+
C76CAF762E112FF30095E48E /* ResponseHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseHandler.swift; sourceTree = "<group>"; };
498+
C76CAF792E1132EA0095E48E /* SatelliteServerResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SatelliteServerResponse.swift; sourceTree = "<group>"; };
499+
C76CAF7B2E1133530095E48E /* WMTSServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WMTSServer.swift; sourceTree = "<group>"; };
484500
C77A4A252DF2AF3100DED8B0 /* SecureInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureInputView.swift; sourceTree = "<group>"; };
485501
C77EEBCE2DE59D3200494CB4 /* UndoMerge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UndoMerge.swift; sourceTree = "<group>"; };
486502
C7ED070E2D70E2EC001FFFE2 /* TokenRefresher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenRefresher.swift; sourceTree = "<group>"; };
@@ -663,6 +679,7 @@
663679
0536DD952B0BD91F00B04C4B /* Network */ = {
664680
isa = PBXGroup;
665681
children = (
682+
C76CAF6F2E1118610095E48E /* APIHandler */,
666683
A48037342BBA8DCB007EE7E4 /* models */,
667684
0536DD962B0BD95100B04C4B /* URLSession+Extension.swift */,
668685
A48037302BBA8C25007EE7E4 /* ApiManager.swift */,
@@ -807,6 +824,8 @@
807824
971575152B5FFD5F0044797C /* Map */ = {
808825
isa = PBXGroup;
809826
children = (
827+
C7672F982E123A3F0084A610 /* MapRepository.swift */,
828+
C76CAF782E1132380095E48E /* Satellite Server */,
810829
971575182B5FFE910044797C /* LocationManagerCoordinator.swift */,
811830
FA50718D2D54E1D200CE9798 /* BingTileOverlay.swift */,
812831
971575162B5FFD6F0044797C /* MapView.swift */,
@@ -1272,6 +1291,25 @@
12721291
C75CC5D82E0D22F4008A94A0 /* LongQuestsResponse.json */,
12731292
);
12741293
path = SampleResponses;
1294+
C76CAF6F2E1118610095E48E /* APIHandler */ = {
1295+
isa = PBXGroup;
1296+
children = (
1297+
C76CAF762E112FF30095E48E /* ResponseHandler.swift */,
1298+
C76CAF742E112FDE0095E48E /* NetworkMonitor.swift */,
1299+
C76CAF722E111A8E0095E48E /* NetworkManager.swift */,
1300+
C76CAF702E11188E0095E48E /* APIManager.swift */,
1301+
);
1302+
path = APIHandler;
1303+
sourceTree = "<group>";
1304+
};
1305+
C76CAF782E1132380095E48E /* Satellite Server */ = {
1306+
isa = PBXGroup;
1307+
children = (
1308+
C755C00D2E12BF79002F1B30 /* SatellitePickerSheet.swift */,
1309+
C76CAF7B2E1133530095E48E /* WMTSServer.swift */,
1310+
C76CAF792E1132EA0095E48E /* SatelliteServerResponse.swift */,
1311+
);
1312+
path = "Satellite Server";
12751313
sourceTree = "<group>";
12761314
};
12771315
FA18CADE2CC7CD46008247F2 /* Kartaview */ = {
@@ -2129,13 +2167,16 @@
21292167
FAEE21DB2DCA1963002F9BEC /* UndoButton.swift in Sources */,
21302168
A4834A3F2B67737500D4F0AA /* StoredChangeset.swift in Sources */,
21312169
FAFDA2082C6E8F2500ECEAE9 /* APIConfiguration.swift in Sources */,
2170+
C76CAF732E111A940095E48E /* NetworkManager.swift in Sources */,
21322171
971342752BBD254200174EBF /* InitialViewModel.swift in Sources */,
21332172
FA5071902D5B31CC00CE9798 /* CreateNoteView.swift in Sources */,
21342173
FA6DB8B32D8853DD0070CCD3 /* UserSettingsView.swift in Sources */,
21352174
FA633CB62DD48C4400324404 /* SessionManager.swift in Sources */,
21362175
059D47312B2C81A9000987FA /* Style.swift in Sources */,
21372176
A4E711A82B57CA4300C9DE08 /* QuestsRepository.swift in Sources */,
21382177
FAFDA2022C6D33C300ECEAE9 /* PosmLoginViewModel.swift in Sources */,
2178+
C755C00E2E12BF7D002F1B30 /* SatellitePickerSheet.swift in Sources */,
2179+
C7672F992E123C720084A610 /* MapRepository.swift in Sources */,
21392180
FAFDA2142C7351CB00ECEAE9 /* APIError.swift in Sources */,
21402181
FA9F381C2DB2FF4B00D7AABF /* ShadowOverlayRenderer.swift in Sources */,
21412182
059D47332B2C83BA000987FA /* Highway.swift in Sources */,
@@ -2154,11 +2195,14 @@
21542195
FA8C74D82C60E95100D28220 /* PosmLogin.swift in Sources */,
21552196
FA5071962D6DD31A00CE9798 /* LongElementQuest.swift in Sources */,
21562197
FAFDA20E2C6F58D600ECEAE9 /* UserProfile.swift in Sources */,
2198+
C76CAF712E1118910095E48E /* APIManager.swift in Sources */,
21572199
FABF3CF82B822F120080EAC9 /* CustomSureAlert.swift in Sources */,
21582200
FA18CAEB2CD0F718008247F2 /* CameraView.swift in Sources */,
21592201
05DBBB642B17204300B6F110 /* RealmOPGeometry.swift in Sources */,
21602202
FA87A8102B68142F000A6BEA /* LoadingView.swift in Sources */,
2203+
C76CAF772E112FF70095E48E /* ResponseHandler.swift in Sources */,
21612204
0536DD922B0BD58800B04C4B /* OAuthService.swift in Sources */,
2205+
C76CAF7C2E11335A0095E48E /* WMTSServer.swift in Sources */,
21622206
973FC0112B4D2D1C00878269 /* QuestAndDescriptionView.swift in Sources */,
21632207
FAFDA2042C6E8BEA00ECEAE9 /* APIEnvironment.swift in Sources */,
21642208
973FC0032B47DE0700878269 /* QuestsVM.swift in Sources */,
@@ -2177,6 +2221,7 @@
21772221
FA18CAE52CC7D0DD008247F2 /* SequenceModel.swift in Sources */,
21782222
FAE481A22DD5EF3800149A48 /* PasswordAuthenticationPopupView.swift in Sources */,
21792223
05DBBB5F2B1263FF00B6F110 /* DatabaseConnector.swift in Sources */,
2224+
C76CAF752E112FDF0095E48E /* NetworkMonitor.swift in Sources */,
21802225
FAF44FC12B30850A004FE664 /* OnboardingView3.swift in Sources */,
21812226
970D5BD12B62B61300C20BE7 /* MapViewController.swift in Sources */,
21822227
FA9FE2D82BAC75390036F618 /* OAuthViewController.swift in Sources */,
@@ -2195,6 +2240,7 @@
21952240
B0CCB98E2B8626C600AA73DE /* ProfileViewVM.swift in Sources */,
21962241
FA8C74C92C57B9AE00D28220 /* LongQuestView.swift in Sources */,
21972242
FAFDA1FF2C6D337800ECEAE9 /* PosmLoginModel.swift in Sources */,
2243+
C76CAF7A2E1133060095E48E /* SatelliteServerResponse.swift in Sources */,
21982244
0536DD942B0BD59900B04C4B /* OAuthError.swift in Sources */,
21992245
973FC0172B4D567900878269 /* WidthView.swift in Sources */,
22002246
FABF3CFD2B8607860080EAC9 /* MeasureWidthContainer.swift in Sources */,

GoInfoGame/GoInfoGame.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

GoInfoGame/GoInfoGame/KeychainManager.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import Security
1111

1212
struct KeychainManager {
1313

14+
enum Keys: String {
15+
case accessToken = "accessToken"
16+
}
17+
1418
static func save(key: String, data: String) -> Bool {
1519
guard let data = data.data(using: .utf8) else { return false }
1620

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// APIManager.swift
3+
// GoInfoGame
4+
//
5+
// Created by Prashamsa on 29/06/25.
6+
//
7+
8+
import Foundation
9+
import Combine
10+
11+
// MARK: - APIRequest
12+
13+
protocol APIRequest {
14+
var urlRequest: URLRequest? { get }
15+
}
16+
17+
// MARK: - APIRequest Extension
18+
19+
extension APIRequest {
20+
func setDefaultValues(urlRequest: URLRequest) -> URLRequest {
21+
var request: URLRequest = urlRequest
22+
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
23+
if let jwtAccessToken = KeychainManager.load(key: KeychainManager.Keys.accessToken.rawValue) {
24+
request.setValue(jwtAccessToken, forHTTPHeaderField: "Authorization")
25+
}
26+
return request
27+
}
28+
}
29+
30+
// MARK: - APIHaandler
31+
32+
protocol APIHandler {
33+
/**
34+
Fetches raw data from an API request asynchronously using Combine.
35+
36+
This method performs a network request based on the given `APIRequest` and returns a `Future` publisher that either emits the retrieved `Data` or an `Error`.
37+
38+
- Parameters:
39+
- request: The `APIRequest` object containing request details such as endpoint, headers, and parameters.
40+
41+
- Returns:
42+
A `Future<Data, Error>` publisher that emits raw `Data` on success or an `Error` on failure.
43+
44+
- Note: The caller is responsible for decoding the returned `Data` into the desired model.
45+
*/
46+
func fetchData(from request: APIRequest) -> Future<Data, Error>
47+
48+
func fetchData(from request: APIRequest) async throws -> (Data, URLResponse)
49+
}
50+
51+
// MARK: - APIManager
52+
53+
class APIManager: APIHandler {
54+
/**
55+
A set to store Combine `AnyCancellable` instances.
56+
57+
This property holds subscriptions to Combine publishers, ensuring they remain active for the lifecycle of the object.
58+
Automatically cancels subscriptions when the instance is deinitialized.
59+
60+
- Note: Use this set to manage memory and prevent subscriptions from being prematurely deallocated.
61+
*/
62+
private var cancellables: Set<AnyCancellable> = []
63+
64+
func fetchData(from request: any APIRequest) -> Future<Data, Error> {
65+
return Future<Data, Error> { [weak self] promise in
66+
guard let self = self, let req = request.urlRequest else {
67+
return promise(.failure(NetworkError.invalidURLRequest))
68+
}
69+
70+
URLSession.shared.dataTaskPublisher(for: req)
71+
.tryMap { (data, response) -> Data in
72+
debugPrint("Response \n\(String(data: data, encoding: .utf8) ?? "")")
73+
guard let response = response as? HTTPURLResponse, (200..<300).contains(response.statusCode) else {
74+
throw NetworkError.badNetwrok
75+
}
76+
return data
77+
}
78+
.sink { completion in
79+
switch completion {
80+
case .failure(let error):
81+
promise(.failure(error))
82+
case .finished:
83+
break
84+
}
85+
} receiveValue: { data in
86+
promise(.success(data))
87+
}
88+
.store(in: &cancellables)
89+
}
90+
}
91+
92+
func fetchData(from request: any APIRequest) async throws -> (Data, URLResponse) {
93+
guard let req = request.urlRequest else {
94+
throw NetworkError.invalidURLRequest
95+
}
96+
97+
return try await URLSession.shared.data(for: req)
98+
}
99+
}

0 commit comments

Comments
 (0)