Point SDK GraphQL to api-app and switch map markers query to getMarkers.
This aligns the app with the new backend endpoint/schema and keeps map marker mapping compatible with the new response shape. Made-with: Cursor
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,10 @@ apollo {
|
||||
service("service") {
|
||||
packageName.set("org.db3.airmq.sdk")
|
||||
schemaFiles.from(file("../app/src/main/graphql/schema.graphqls"))
|
||||
introspection {
|
||||
endpointUrl.set("https://api-app.airmq.cc/graphql")
|
||||
schemaFile.set(file("../app/src/main/graphql/schema.graphqls"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +60,6 @@ dependencies {
|
||||
// Hilt
|
||||
implementation(libs.hilt.android)
|
||||
ksp(libs.hilt.compiler)
|
||||
|
||||
testImplementation(libs.junit)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
query MapMarkers($isOnline: Boolean) {
|
||||
locations(filter: { isOnline: $isOnline }) {
|
||||
query MapMarkers {
|
||||
getMarkers {
|
||||
_id
|
||||
name
|
||||
city
|
||||
isOnline
|
||||
text
|
||||
latitude
|
||||
longitude
|
||||
metricList
|
||||
currentValue {
|
||||
value
|
||||
values {
|
||||
PMS25
|
||||
Count
|
||||
}
|
||||
|
||||
@@ -8,24 +8,32 @@ import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
import org.db3.airmq.sdk.auth.ApiTokenStore
|
||||
import org.db3.airmq.sdk.auth.AuthService
|
||||
import org.db3.airmq.sdk.auth.BackendAuthGateway
|
||||
import org.db3.airmq.sdk.auth.BackendAuthGatewayImpl
|
||||
import org.db3.airmq.sdk.auth.FirebaseAuthService
|
||||
import org.db3.airmq.sdk.auth.FirebaseSessionManager
|
||||
import org.db3.airmq.sdk.auth.FirebaseSessionManagerImpl
|
||||
import org.db3.airmq.sdk.auth.SharedPreferencesApiTokenStore
|
||||
import org.db3.airmq.sdk.map.MapServiceImpl
|
||||
import org.db3.airmq.sdk.map.MapService
|
||||
import org.db3.airmq.sdk.settings.SettingsService
|
||||
import org.db3.airmq.sdk.settings.SettingsServiceImpl
|
||||
import org.db3.airmq.sdk.network.ApolloAuthInterceptor
|
||||
import org.db3.airmq.sdk.network.ApolloLoggingInterceptor
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object SDKModule {
|
||||
private const val API_URL = "https://api.airmq.cc"
|
||||
private const val API_URL = "https://api-app.airmq.cc/"
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideApolloClient(): ApolloClient {
|
||||
fun provideApolloClient(apiTokenStore: ApiTokenStore): ApolloClient {
|
||||
return ApolloClient.Builder()
|
||||
.serverUrl(API_URL)
|
||||
.addInterceptor(ApolloAuthInterceptor(apiTokenStore))
|
||||
.addInterceptor(ApolloLoggingInterceptor())
|
||||
.build()
|
||||
}
|
||||
@@ -42,6 +50,18 @@ abstract class SDKBindModule {
|
||||
@Singleton
|
||||
abstract fun bindAuthService(impl: FirebaseAuthService): AuthService
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
abstract fun bindApiTokenStore(impl: SharedPreferencesApiTokenStore): ApiTokenStore
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
abstract fun bindFirebaseSessionManager(impl: FirebaseSessionManagerImpl): FirebaseSessionManager
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
abstract fun bindBackendAuthGateway(impl: BackendAuthGatewayImpl): BackendAuthGateway
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
abstract fun bindMapService(impl: MapServiceImpl): MapService
|
||||
|
||||
@@ -5,17 +5,20 @@ import org.db3.airmq.sdk.MapMarkersQuery
|
||||
import org.db3.airmq.sdk.map.domain.MapItem
|
||||
|
||||
class ApolloMapItemMapper @Inject constructor() {
|
||||
fun toDomain(location: MapMarkersQuery.Location, index: Int): MapItem? {
|
||||
val id = location._id.ifBlank { "location-$index" }
|
||||
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 { "marker-$index" } ?: "marker-$index"
|
||||
val latestValues = marker.values?.firstOrNull()
|
||||
return MapItem(
|
||||
id = id,
|
||||
title = location.name.ifBlank { id },
|
||||
city = location.city?.ifBlank { null },
|
||||
latitude = location.latitude,
|
||||
longitude = location.longitude,
|
||||
isOnline = location.isOnline ?: false,
|
||||
dustValue = location.currentValue?.PMS25?.toDouble(),
|
||||
radioactivityValue = location.currentValue?.Count?.toDouble()
|
||||
title = marker.name?.ifBlank { id } ?: id,
|
||||
city = marker.text?.ifBlank { null },
|
||||
latitude = latitude,
|
||||
longitude = longitude,
|
||||
isOnline = marker.value != null,
|
||||
dustValue = latestValues?.PMS25?.toDouble() ?: marker.value?.toDouble(),
|
||||
radioactivityValue = latestValues?.Count?.toDouble()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.db3.airmq.sdk.map
|
||||
|
||||
import android.util.Log
|
||||
import com.apollographql.apollo.ApolloClient
|
||||
import com.apollographql.apollo.api.Optional
|
||||
import javax.inject.Inject
|
||||
import org.db3.airmq.sdk.MapMarkersQuery
|
||||
import org.db3.airmq.sdk.map.domain.MapItem
|
||||
@@ -13,17 +12,8 @@ class MapServiceImpl @Inject constructor(
|
||||
) : MapService {
|
||||
override suspend fun fetchMapItems(showOfflineDevices: Boolean): List<MapItem> {
|
||||
Log.d(TAG, "Executing MapMarkers Apollo query")
|
||||
val isOnlineFilter: Optional<Boolean?> = if (showOfflineDevices) {
|
||||
Optional.Absent
|
||||
} else {
|
||||
Optional.Present(true)
|
||||
}
|
||||
val response = apolloClient
|
||||
.query(
|
||||
MapMarkersQuery(
|
||||
isOnline = isOnlineFilter
|
||||
)
|
||||
)
|
||||
.query(MapMarkersQuery())
|
||||
.execute()
|
||||
|
||||
response.errors?.firstOrNull()?.let { gqlError ->
|
||||
@@ -31,10 +21,10 @@ class MapServiceImpl @Inject constructor(
|
||||
throw IllegalStateException(gqlError.message)
|
||||
}
|
||||
|
||||
val mappedItems = response.data?.locations
|
||||
val mappedItems = response.data?.getMarkers
|
||||
.orEmpty()
|
||||
.filterNotNull()
|
||||
.mapIndexedNotNull { index, location -> mapper.toDomain(location, index) }
|
||||
.mapIndexedNotNull { index, marker -> mapper.toDomain(marker, index) }
|
||||
Log.d(TAG, "MapMarkers Apollo query returned ${mappedItems.size} items")
|
||||
return mappedItems
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user