diff --git a/build.gradle.kts b/build.gradle.kts index b41c6c31..79d7d3e1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,6 +11,7 @@ plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.kotlin.serialization) apply false alias(libs.plugins.hilt) apply false alias(libs.plugins.verify.detekt) apply false } diff --git a/core/data/build.gradle.kts b/core/data/build.gradle.kts index f0d09905..db62ecb6 100644 --- a/core/data/build.gradle.kts +++ b/core/data/build.gradle.kts @@ -1,4 +1,16 @@ plugins { - id("droidknights.kotlin.library") - id("droidknights.kotlin.hilt") + id("droidknights.android.library") + id("droidknights.android.hilt") + id("kotlinx-serialization") +} + +android { + namespace = "com.droidknights.app2023.core.data" +} + +dependencies { + implementation(libs.retrofit.core) + implementation(libs.retrofit.kotlin.serialization) + implementation(libs.okhttp.logging) + implementation(libs.kotlinx.serialization.json) } diff --git a/core/data/src/main/AndroidManifest.xml b/core/data/src/main/AndroidManifest.xml new file mode 100644 index 00000000..568741e5 --- /dev/null +++ b/core/data/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt new file mode 100644 index 00000000..6723cc78 --- /dev/null +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt @@ -0,0 +1,40 @@ +package com.droidknights.app2023.core.data.di + +import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import kotlinx.serialization.json.Json +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import retrofit2.Retrofit +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal object ApiModule { + private const val BASE_URL = "https://raw.githubusercontent.com/" + + + @Provides + @Singleton + fun provideOkhttpClient(): OkHttpClient = OkHttpClient.Builder().build() + + @Provides + @Singleton + fun provideRetrofit( + okHttpClient: OkHttpClient, + json: Json, + ): Retrofit = Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(json.asConverterFactory("application/json".toMediaType())) + .client(okHttpClient) + .build() + + @Provides + @Singleton + fun provideJson(): Json = Json { + ignoreUnknownKeys = true + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7946e2f8..cdfa3f8f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,8 +9,14 @@ androidxComposeMaterial3 = "1.1.0" androidxActivity = "1.7.2" hilt = "2.46.1" +okhttp = "4.11.0" +retrofit = "2.9.0" +retrofitKotlinxSerializationJson = "1.0.0" +kotlinxSerializationJson = "1.5.1" + junit4 = "4.13.2" kotlin = "1.8.21" + androidxTestExt = "1.1.4" androidxEspresso = "3.5.0" kotest = "5.6.2" @@ -42,6 +48,11 @@ hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref hilt-android-testing = { group = "com.google.dagger", name = "hilt-android-testing", version.ref = "hilt" } hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" } +okhttp-logging = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp" } +retrofit-core = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" } +retrofit-kotlin-serialization = { group = "com.jakewharton.retrofit", name = "retrofit2-kotlinx-serialization-converter", version.ref = "retrofitKotlinxSerializationJson" } +kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" } + junit4 = { group = "junit", name = "junit", version.ref = "junit4" } androidx-test-ext = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "androidxTestExt" } androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidxEspresso" } @@ -62,5 +73,6 @@ android-application = { id = "com.android.application", version.ref = "androidGr android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } verify-detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }