Update map marker mapping for locations query.
Switch MapMarkers handling from getMarkers to locations, and align mapper fields with the new Location payload while preserving MapItem coordinates and online status. Made-with: Cursor
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
query MapMarkers($isOnline: Boolean!) {
|
||||
getMarkers(filter: { isOnline: $isOnline }) {
|
||||
locations(filter: { isOnline: $isOnline }) {
|
||||
_id
|
||||
name
|
||||
city
|
||||
isOnline
|
||||
latitude
|
||||
longitude
|
||||
text
|
||||
metricList
|
||||
currentValue {
|
||||
PMS25
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,15 @@ import org.db3.airmq.sdk.MapMarkersQuery
|
||||
import org.db3.airmq.sdk.map.domain.MapItem
|
||||
|
||||
class ApolloMapItemMapper @Inject constructor() {
|
||||
fun toDomain(marker: MapMarkersQuery.GetMarker, index: Int): MapItem? {
|
||||
val latitude = marker.latitude ?: return null
|
||||
val longitude = marker.longitude ?: return null
|
||||
val id = marker._id?.ifBlank { null } ?: "marker-$index"
|
||||
fun toDomain(location: MapMarkersQuery.Location, index: Int): MapItem? {
|
||||
val id = location._id.ifBlank { "location-$index" }
|
||||
return MapItem(
|
||||
id = id,
|
||||
title = marker.name?.ifBlank { null } ?: marker.text?.ifBlank { null } ?: id,
|
||||
city = null,
|
||||
latitude = latitude,
|
||||
longitude = longitude,
|
||||
isOnline = false
|
||||
title = location.name.ifBlank { id },
|
||||
city = location.city?.ifBlank { null },
|
||||
latitude = location.latitude,
|
||||
longitude = location.longitude,
|
||||
isOnline = location.isOnline ?: false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ class MapServiceImpl @Inject constructor(
|
||||
throw IllegalStateException(gqlError.message)
|
||||
}
|
||||
|
||||
val mappedItems = response.data?.getMarkers
|
||||
val mappedItems = response.data?.locations
|
||||
.orEmpty()
|
||||
.filterNotNull()
|
||||
.mapIndexedNotNull { index, marker -> mapper.toDomain(marker, index) }
|
||||
.mapIndexedNotNull { index, location -> mapper.toDomain(location, index) }
|
||||
Log.d(TAG, "MapMarkers Apollo query returned ${mappedItems.size} items")
|
||||
return mappedItems
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user