Skip to content

Commit e038d77

Browse files
authored
Merge pull request #289 from TaskarCenterAtUW/TASK-2360-Update-long-quest-and-imagery-data-handling
Updated handling long quests and imagery data handling
2 parents 407efb7 + cda3881 commit e038d77

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

GoInfoGame/GoInfoGame/Network/APIEndPoint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct APIEndpoint {
3737
]
3838
return APIEndpoint(path: "/workspaces/mine?lat=\(location.latitude.roundedTo7Digits())&lon=\(location.longitude.roundedTo7Digits())&radius=\(radius)&gig_only=\(gig_only)", method: "GET", body: nil, headers: header, formData: nil)}
3939

40-
static let fetchLongQuests = { (workspaceId: String) in APIEndpoint(path: "/workspaces/\(workspaceId)/quests/long", method: "GET", body: nil, headers: ["Content-Type":"application/json"], formData: nil) }
40+
static let fetchWorkspaceDetails = { (workspaceId: String) in APIEndpoint(path: "/workspaces/\(workspaceId)", method: "GET", body: nil, headers: ["Content-Type":"application/json"], formData: nil) }
4141

4242
static let fetchOSMElements = { (left: Double, bottom: Double, right: Double, top: Double, workspaceID: String) in
4343
let header = [

GoInfoGame/GoInfoGame/Network/models/WorkspacesResponse.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Foundation
1414

1515
// MARK: - WorkSpacesResponse
16-
class WorkSpacesResponse: Codable {
16+
class WorkSpacesResponse: Decodable {
1717
let workspaces: [Workspace]
1818

1919
init(workspaces: [Workspace]) {
@@ -22,12 +22,13 @@ class WorkSpacesResponse: Codable {
2222
}
2323

2424
// MARK: - Workspace
25-
struct Workspace: Codable,Hashable {
25+
struct Workspace: Decodable {
2626
let id: Int
2727
let title: String
2828
let type: String?
2929
let externalAppAccess: Int
3030
let imageryList: SatelliteServers?
31+
let longFormQuest: LongFormResponse?
3132

3233
init(from decoder: Decoder) throws {
3334
let container = try decoder.container(keyedBy: CodingKeys.self)
@@ -36,11 +37,14 @@ struct Workspace: Codable,Hashable {
3637
type = try container.decodeIfPresent(String.self, forKey: .type) ?? "osw"
3738
externalAppAccess = try container.decode(Int.self, forKey: .externalAppAccess)
3839
imageryList = try container.decodeIfPresent(SatelliteServers.self, forKey: .imageryList)
40+
longFormQuest = try container.decodeIfPresent(LongFormResponse.self, forKey: .longFormQuest)
3941
}
4042

41-
enum CodingKeys: String, CodingKey {
42-
case id, title, type, externalAppAccess, imageryList
43-
}
43+
enum CodingKeys: String, CodingKey {
44+
case id, title, type, externalAppAccess
45+
case imageryList = "imageryListDef"
46+
case longFormQuest = "longFormQuestDef"
47+
}
4448
}
4549

4650
// MARK: - Polygon

GoInfoGame/GoInfoGame/UI/InitialView/InitialViewModel.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ class InitialViewModel: ObservableObject {
7474

7575
isLoading = true
7676

77-
ApiManager.shared.performRequest(to: .fetchLongQuests(workspaceId), setupType: .workspace, modelType: LongFormResponse.self) { [weak self] result in
77+
ApiManager.shared.performRequest(to: .fetchWorkspaceDetails(workspaceId), setupType: .workspace, modelType: Workspace.self) { [weak self] result in
7878
guard let self = self else { return completion(false, "Object memory released.") }
7979
DispatchQueue.main.async { [unowned self] in
8080
switch result {
81-
case .success(let longQuestsResponse):
81+
case .success(let workspaces):
8282

83+
guard let longQuestsResponse = workspaces.longFormQuest else {
84+
self.isLoading = false
85+
completion(false, "Please configure longform." )
86+
return
87+
}
8388
// Validate quest query
8489
do {
8590
for item in longQuestsResponse.elements {
@@ -114,14 +119,9 @@ class InitialViewModel: ObservableObject {
114119
self.isLoading = false
115120
completion(true, "")
116121
case .failure(let error):
117-
print("ERROR FOR LONG FORM JSON IS ----?>>>>>>\(error.localizedDescription)")
122+
print("ERROR from workspace details api ----?>>>>>>\(error.localizedDescription)")
118123
self.isLoading = false
119-
if error.localizedDescription.contains("empty") {
120-
completion(false, "Please configure longform." )
121-
} else {
122-
completion(false, "Unable to load quests.(invalid JSON)")
123-
}
124-
124+
completion(false, "Not able to load the workspace details. Please try again later." )
125125
}
126126
}
127127
}

0 commit comments

Comments
 (0)