Skip to content

Commit 0327068

Browse files
committed
Database clear is rectified
Rectified the issue with database clear
1 parent c9d4e9c commit 0327068

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

GoInfoGame/GoInfoGame/DataBase/DatabaseConnector.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class DatabaseConnector {
130130
print("Error clearing DB")
131131
}
132132
}
133+
134+
133135

134136
func saveElements(_ elements: [OSMWay]) {
135137
do {

GoInfoGame/GoInfoGame/Network/ApiManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class ApiManager {
168168
} catch {
169169
print("Failed to decode data: \(error.localizedDescription)")
170170
if let dataString = String(data: data, encoding: .utf8), !dataString.isEmpty {
171-
completion(.failure(APIError.custom("Not a valid JSON")))
171+
completion(.failure(APIError.custom("Not a valid JSON \(dataString)")))
172172
} else {
173173
completion(.failure(APIError.custom("Empty JSON")))
174174
}

GoInfoGame/GoInfoGame/UI/InitialView/InitialView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct WorkspacesListView: View {
135135
VStack(spacing: 20) {
136136
ForEach(workspaces.filter({$0.type == "osw" && $0.externalAppAccess == 1}), id: \.id) { workspace in
137137
Button {
138+
viewModel.checkAndDeleteWorkspaceDB(workspaceId: "\(workspace.id)")
138139
viewModel.fetchLongQuestsFor(workspaceId: "\(workspace.id)", completion: { success, errorMessage in
139140
if success {
140141
self.shouldNavigateToMapView = true

GoInfoGame/GoInfoGame/UI/InitialView/InitialViewModel.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ class InitialViewModel: ObservableObject {
4949
}
5050
}
5151

52+
func checkAndDeleteWorkspaceDB(workspaceId: String) {
53+
if let existingWorkspaceId = KeychainManager.load(key: "workspaceID") {
54+
if existingWorkspaceId != workspaceId {
55+
print("User is changing the workpace. Delete all existing data from DB")
56+
DatabaseConnector.shared.clearDB()
57+
}
58+
}
59+
60+
61+
}
62+
5263
func fetchLongQuestsFor(workspaceId: String,completion: @escaping (Bool, String?) -> Void) {
5364

5465
isLoading = true

GoInfoGame/GoInfoGame/UI/Profile/ProfileView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ struct LoggedInView: View {
162162
_ = KeychainManager.delete(key: "refreshToken")
163163
UserDefaults.standard.removeObject(forKey: "accessToken_expire_in")
164164
UserDefaults.standard.removeObject(forKey: "accessToken_Generate")
165+
// Removing all the data from database as well.
166+
DatabaseConnector.shared.clearDB()
165167
accessToken = nil
166168
} label: {
167169
Text("LOGOUT")

GoInfoGame/GoInfoGame/quests/QuestProtocols.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class QuestBase {
7171
}
7272
catch {
7373
print("❌ Undo failed: \(error)")
74+
MapViewPublisher.shared.dismissSheet.send(.failed("Failed to Undo changes. Please try again"))
7475
}
7576
})
7677
}

0 commit comments

Comments
 (0)