diff --git a/shared/data/src/androidMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.android.kt b/shared/data/src/androidMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.android.kt deleted file mode 100644 index 8fca1101..00000000 --- a/shared/data/src/androidMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.android.kt +++ /dev/null @@ -1,51 +0,0 @@ -package fr.androidmakers.store.graphql - -import android.content.Context -import android.service.autofill.UserData -import com.apollographql.apollo3.ApolloClient -import com.apollographql.apollo3.api.http.HttpRequest -import com.apollographql.apollo3.api.http.HttpResponse -import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory -import com.apollographql.apollo3.cache.normalized.normalizedCache -import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.apollo3.network.http.HttpInterceptor -import com.apollographql.apollo3.network.http.HttpInterceptorChain -import com.google.firebase.auth.ktx.auth -import com.google.firebase.ktx.Firebase -import fr.androidmakers.domain.repo.UserRepository -import fr.androidmakers.store.firebase.FirebaseUserRepository -import java.util.PrimitiveIterator - -actual class ApolloClientBuilder( - context: Context, - private val url: String, - private val conference: String, - private val userRepository: UserRepository, -) { - private val memoryCacheFactory = MemoryCacheFactory(20_000_000).chain(SqlNormalizedCacheFactory(context)) - actual fun build(): ApolloClient { - return ApolloClient.Builder() - .serverUrl(url) - .addHttpInterceptor(object : HttpInterceptor { - override suspend fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse { - return chain.proceed( - request.newBuilder() - .addHeader("conference", conference) - .apply { - /** - * - */ - val token = userRepository.getIdToken() - if (token != null) { - addHeader("Authorization", "Bearer $token") - } - } - .build() - ) - } - }) - .normalizedCache(memoryCacheFactory) - .build() - - } -} diff --git a/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.kt b/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.kt new file mode 100644 index 00000000..0f15e951 --- /dev/null +++ b/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.kt @@ -0,0 +1,39 @@ +package fr.androidmakers.store.graphql + +import com.apollographql.apollo3.ApolloClient +import com.apollographql.apollo3.api.http.HttpRequest +import com.apollographql.apollo3.api.http.HttpResponse +import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory +import com.apollographql.apollo3.cache.normalized.normalizedCache +import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory +import com.apollographql.apollo3.network.http.HttpInterceptor +import com.apollographql.apollo3.network.http.HttpInterceptorChain +import fr.androidmakers.domain.repo.UserRepository + +fun ApolloClient( + sqlNormalizedCacheFactory: SqlNormalizedCacheFactory, + userRepository: UserRepository, +): ApolloClient { + val memoryCacheFactory = MemoryCacheFactory(20_000_000).chain(sqlNormalizedCacheFactory) + return ApolloClient.Builder() + .serverUrl("https://androidmakers.fr/graphql") + .addHttpInterceptor(object : HttpInterceptor { + override suspend fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse { + return chain.proceed( + request.newBuilder() + .apply { + /** + * + */ + val token = userRepository.getIdToken() + if (token != null) { + addHeader("Authorization", "Bearer $token") + } + } + .build() + ) + } + }) + .normalizedCache(memoryCacheFactory) + .build() +} diff --git a/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.kt b/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.kt deleted file mode 100644 index a018d7a0..00000000 --- a/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.kt +++ /dev/null @@ -1,7 +0,0 @@ -package fr.androidmakers.store.graphql - -import com.apollographql.apollo3.ApolloClient - -expect class ApolloClientBuilder { - fun build(): ApolloClient -} diff --git a/shared/data/src/iosMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.ios.kt b/shared/data/src/iosMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.ios.kt deleted file mode 100644 index 313d1a18..00000000 --- a/shared/data/src/iosMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.ios.kt +++ /dev/null @@ -1,35 +0,0 @@ -package fr.androidmakers.store.graphql - -import com.apollographql.apollo3.ApolloClient -import com.apollographql.apollo3.api.http.HttpRequest -import com.apollographql.apollo3.api.http.HttpResponse -import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory -import com.apollographql.apollo3.cache.normalized.normalizedCache -import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.apollo3.network.http.HttpInterceptor -import com.apollographql.apollo3.network.http.HttpInterceptorChain - -actual class ApolloClientBuilder( - private val url: String, - private val conference: String, - private val token: String -) { - private val cacheFactory = MemoryCacheFactory(20_000_000).chain(SqlNormalizedCacheFactory()) - - actual fun build(): ApolloClient { - return ApolloClient.Builder() - .serverUrl(url) - .addHttpInterceptor(object : HttpInterceptor { - override suspend fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse { - return chain.proceed( - request.newBuilder() - .addHeader("conference", conference) - //.addHeader("Authorization", "Bearer $token") - .build() - ) - } - } - ).normalizedCache(cacheFactory) - .build() - } -} diff --git a/shared/di/build.gradle.kts b/shared/di/build.gradle.kts index 97427121..7302a408 100644 --- a/shared/di/build.gradle.kts +++ b/shared/di/build.gradle.kts @@ -24,6 +24,7 @@ kotlin { commonMain.dependencies { implementation(project(":shared:domain")) implementation(project(":shared:data")) + implementation(libs.apollo.normalized.cache.sqlite) api(libs.koin.core) } diff --git a/shared/di/src/androidMain/kotlin/fr/androidmakers/di/DataModule.android.kt b/shared/di/src/androidMain/kotlin/fr/androidmakers/di/DataModule.android.kt index 68385543..1cc8ea36 100644 --- a/shared/di/src/androidMain/kotlin/fr/androidmakers/di/DataModule.android.kt +++ b/shared/di/src/androidMain/kotlin/fr/androidmakers/di/DataModule.android.kt @@ -2,17 +2,16 @@ package fr.androidmakers.di import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences -import fr.androidmakers.store.graphql.ApolloClientBuilder +import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory +import fr.androidmakers.store.graphql.ApolloClient import fr.androidmakers.store.local.createDataStore import org.koin.android.ext.koin.androidContext import org.koin.dsl.module actual val dataPlatformModule = module { single { - ApolloClientBuilder( - androidContext(), - "https://androidmakers.fr/graphql", - "androidmakers2024", + ApolloClient( + SqlNormalizedCacheFactory(context = get()), get() ) } diff --git a/shared/di/src/commonMain/kotlin/fr/androidmakers/di/DataModule.kt b/shared/di/src/commonMain/kotlin/fr/androidmakers/di/DataModule.kt index 8b10f657..f456bf5d 100644 --- a/shared/di/src/commonMain/kotlin/fr/androidmakers/di/DataModule.kt +++ b/shared/di/src/commonMain/kotlin/fr/androidmakers/di/DataModule.kt @@ -8,7 +8,6 @@ import fr.androidmakers.domain.repo.SpeakersRepository import fr.androidmakers.domain.repo.UserRepository import fr.androidmakers.domain.repo.VenueRepository import fr.androidmakers.store.firebase.FirebaseUserRepository -import fr.androidmakers.store.graphql.ApolloClientBuilder import fr.androidmakers.store.graphql.PartnersGraphQLRepository import fr.androidmakers.store.graphql.RoomsGraphQLRepository import fr.androidmakers.store.graphql.SessionsGraphQLRepository @@ -22,7 +21,6 @@ import org.koin.dsl.module expect val dataPlatformModule: Module val dataModule = module { - single { get().build() } single { PartnersGraphQLRepository(get()) } single { RoomsGraphQLRepository(get()) } single { SessionsGraphQLRepository(get()) } diff --git a/shared/di/src/iosMain/kotlin/fr/androidmakers/di/DataModule.ios.kt b/shared/di/src/iosMain/kotlin/fr/androidmakers/di/DataModule.ios.kt index 3bbf8bb1..bdea2011 100644 --- a/shared/di/src/iosMain/kotlin/fr/androidmakers/di/DataModule.ios.kt +++ b/shared/di/src/iosMain/kotlin/fr/androidmakers/di/DataModule.ios.kt @@ -2,7 +2,8 @@ package fr.androidmakers.di import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences -import fr.androidmakers.store.graphql.ApolloClientBuilder +import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory +import fr.androidmakers.store.graphql.ApolloClient import fr.androidmakers.store.local.createDataStore import kotlinx.cinterop.ExperimentalForeignApi import org.koin.dsl.module @@ -13,7 +14,12 @@ import platform.Foundation.NSUserDomainMask @OptIn(ExperimentalForeignApi::class) actual val dataPlatformModule = module { - single { ApolloClientBuilder("https://androidmakers.fr/graphql", "androidmakers2024", "") } + single { + ApolloClient( + SqlNormalizedCacheFactory(), + get() + ) + } single> { createDataStore { diff --git a/shared/domain/src/commonMain/kotlin/fr/androidmakers/domain/interactor/SetSessionBookmarkUseCase.kt b/shared/domain/src/commonMain/kotlin/fr/androidmakers/domain/interactor/SetSessionBookmarkUseCase.kt index 62c952be..e21d724d 100644 --- a/shared/domain/src/commonMain/kotlin/fr/androidmakers/domain/interactor/SetSessionBookmarkUseCase.kt +++ b/shared/domain/src/commonMain/kotlin/fr/androidmakers/domain/interactor/SetSessionBookmarkUseCase.kt @@ -10,10 +10,9 @@ class SetSessionBookmarkUseCase( private val bookmarksRepository: BookmarksRepository ) { suspend operator fun invoke(sessionId: String, isBookmark: Boolean) { + bookmarksRepository.setBookmarked(sessionId, isBookmark) userRepository.getUser()?.id?.let { token -> - sessionsRepository.setBookmark(token, sessionId, isBookmark) + sessionsRepository.setBookmark(token, sessionId, isBookmark) } - - bookmarksRepository.setBookmarked(sessionId, isBookmark) } }