@@ -23,6 +23,11 @@ class DatabaseConnector {
2323 }
2424 }
2525
26+ /**
27+ Saves the OPElements into the database. This method does not remove the old data. However, it updates the
28+ data with same id
29+ @param elements List of OPElement
30+ */
2631 func saveElements( _ elements: [ OPElement ] ) {
2732 // Save the elements appropriately
2833 // Get the ways and nodes out
@@ -84,7 +89,10 @@ class DatabaseConnector {
8489 print ( " Elements to be skipped or something happened " )
8590 }
8691 }
87-
92+ /**
93+ Earlier implementation of saveElements. This used to save only the Way type of objects.
94+ This is not used anymore
95+ */
8896 func saveElements( _ elements: [ OPWay ] ) {
8997 do {
9098 try realm. write {
@@ -128,15 +136,25 @@ class DatabaseConnector {
128136 print ( " Error saving elements to Realm: \( error) " )
129137 }
130138 }
131-
139+ /**
140+ Fetches all the StoredNodes in the Database
141+ @returns a Results object containing StoredNodes
142+ */
132143 func getNodes( ) -> Results < StoredNode > {
133144 return realm. objects ( StoredNode . self)
134145 }
135-
146+ /**
147+ Fetches all the storedWays in the Database
148+ @returns a Results object containing StoredWay
149+ */
136150 func getWays( ) -> Results < StoredWay > {
137151 return realm. objects ( StoredWay . self)
138152 }
139-
153+ /**
154+ Fetches the center of a given StoredWay
155+ @param id String value of the way ID
156+ @returns CLLocationCoordinate2D the center location
157+ */
140158 func getCenterForWay( id: String ) -> CLLocationCoordinate2D ? {
141159 // Get all the objects for the way
142160 guard let way = realm. object ( ofType: StoredWay . self, forPrimaryKey: Int ( id) ) else {
@@ -159,15 +177,28 @@ class DatabaseConnector {
159177 return CLLocationCoordinate2D ( latitude: 0 , longitude: 0 )
160178
161179 }
162-
180+ /**
181+ Fetches a single node from the database
182+ @param id: String value of the node ID
183+ @return StoredNode
184+ */
163185 func getNode( id: String ) -> StoredNode ? {
164186 return realm. object ( ofType: StoredNode . self, forPrimaryKey: Int ( id) )
165187 }
166-
188+ /**
189+ Fetches single Way from the database
190+ @param id: String value of the wayId
191+ @return StoredWay
192+ */
167193 func getWay( id: String ) -> StoredWay ? {
168194 return realm. object ( ofType: StoredWay . self, forPrimaryKey: Int ( id) )
169195 }
170-
196+ /**
197+ Adds tags to the existing node and stores the same
198+ @param id : String value of the node ID
199+ @param tags [String:String] map of the added tags
200+ @return StoredNode
201+ */
171202 func addNodeTags( id: String , tags: [ String : String ] ) -> StoredNode ? {
172203 guard let theNode = getNode ( id: id) else { return nil }
173204 do {
@@ -185,7 +216,12 @@ class DatabaseConnector {
185216 return theNode
186217 }
187218
188-
219+ /**
220+ Adds tags to the existing way and stores the same
221+ @param id: String value of the way ID
222+ @param tags `[String:String]` map of the added tags
223+ @return `StoredWay`
224+ */
189225 func addWayTags( id: String , tags: [ String : String ] ) -> StoredWay ? {
190226 guard let theWay = getWay ( id: id) else { return nil }
191227
@@ -196,7 +232,13 @@ class DatabaseConnector {
196232 realm. add ( theWay, update: . all) // Test this
197233 return theWay
198234 }
199-
235+ /**
236+ Creates a changeset for an element with specific ID. This does not store the updated nodes. That is to be done separately
237+ - parameter id: String id of the changed element
238+ - parameter type: StoredElementEnum type of the changed element (either way or node)
239+ - parameter tags [String:String] tags changed with this
240+ - Returns: An instance of `StoredChangeset`
241+ */
200242 func createChangeset( id: String , type: StoredElementEnum , tags: [ String : String ] ) -> StoredChangeset ? {
201243 let storedChangeset = StoredChangeset ( )
202244 storedChangeset. elementId = id
@@ -215,15 +257,20 @@ class DatabaseConnector {
215257 }
216258 return storedChangeset
217259 }
218-
260+ /// Fetches the changeset objects from the database
261+ /// - parameter synced: Optional variable of whether synced or non synced
262+ /// - Returns: an instance of `Results<StoredChangeset>`
219263 func getChangesets( synced: Bool = false ) -> Results < StoredChangeset > {
220264
221265 if ( synced == true ) {
222266 return realm. objects ( StoredChangeset . self) . where ( { $0. changesetId != - 1 } )
223267 }
224268 return realm. objects ( StoredChangeset . self) . where ( { $0. changesetId == - 1 } )
225269 }
226-
270+ /// Assigns changesetId for a stored changeset
271+ /// - parameter obj: Internal id for the changeset in the database (unique ID)
272+ /// - parameter changesetId: Assigned changeset ID from the server
273+ /// - Returns updated `StoredChangeset`
227274 func assignChangesetId( obj: String , changesetId: Int ) -> StoredChangeset ? {
228275 guard let changeset = realm. object ( ofType: StoredChangeset . self, forPrimaryKey: obj) else {
229276 return nil
0 commit comments