Skip to content

Commit b106004

Browse files
committed
Minor changes to the system
Minor changes to the apis
1 parent 090dd11 commit b106004

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

GoInfoGame/GoInfoGame/data/DatasyncManager.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ class DatasyncManager {
7777
}
7878
}
7979
// TODO: Add logic to sync Way
80+
for (key,way) in waysToSync {
81+
var payload = way.asOSMWay()
82+
// update the way
83+
let result = await syncWay(way: &payload)
84+
switch result{
85+
case .success(let isFinished):
86+
print("Synced \(payload)")
87+
DispatchQueue.main.async {
88+
// your code here
89+
self.dbInstance.assignChangesetId(obj: key, changesetId: payload.changeset)
90+
}
91+
92+
case .failure(let error):
93+
print("Failed to sync \(payload)")
94+
}
95+
96+
}
8097
isSynching = false
8198

8299
}
@@ -126,6 +143,16 @@ class DatasyncManager {
126143
}
127144
}
128145

146+
// utility function to act as substitute for osmConnection functions
147+
func updateWay(way: inout OSMWay) async -> Result<Int,Error> {
148+
await withCheckedContinuation { continuation in
149+
osmConnection.updateWay(way: &way, tags: way.tags) { result in
150+
continuation.resume(returning:result)
151+
}
152+
}
153+
}
154+
155+
129156

130157
/**
131158
Syncs the node along with the updated
@@ -149,4 +176,24 @@ class DatasyncManager {
149176
return .failure(error)
150177
}
151178
}
179+
180+
func syncWay(way: inout OSMWay) async -> Result<Bool,Error> {
181+
do {
182+
// open changeset
183+
let changesetId = try await openChangeset().get()
184+
// update node
185+
way.changeset = changesetId
186+
// close changeset
187+
let newVersion = try await updateWay(way: &way).get()
188+
way.version = newVersion
189+
// Give back the new version and other stuff.
190+
let closeResult = try await closeChangeset(id: String(changesetId)).get()
191+
192+
return .success(true)
193+
194+
} catch (let error){
195+
print(error)
196+
return .failure(error)
197+
}
198+
}
152199
}

GoInfoGame/osmapi/OSMConnection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public class OSMConnection {
131131

132132
}
133133

134-
func updateWay(way: inout OSMWay, tags:[String:String], completion: @escaping((Result<Int,Error>)->Void)){
134+
public func updateWay(way: inout OSMWay, tags:[String:String], completion: @escaping((Result<Int,Error>)->Void)){
135135
// Have to do this.
136136
let urlString = self.baseUrl.appending("way/").appending(String(way.id))
137137
guard let url = URL(string: urlString) else {

0 commit comments

Comments
 (0)