Skip to content

Commit

Permalink
update data logic (#12)
Browse files Browse the repository at this point in the history
* chore: add kotlin.serialization

* chore: update ApiFactory
  • Loading branch information
giovannijunseokim authored Apr 1, 2024
1 parent 486e37e commit e3aba7b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.jetbrainsKotlinAndroid)
alias(libs.plugins.ktlint)
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
kotlin("plugin.serialization")
}

android {
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/univ/earthbreaker/namu/data/ApiFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ object ApiFactory {

val retrofitForGrowTreeServer: Retrofit by lazy {
Retrofit.Builder().baseUrl(BuildConfig.GROW_TREE_BASE_URL).client(client)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())).build()
.addConverterFactory(
Json.asConverterFactory("application/json".toMediaType()),
).build()
}

val retrofitForChatGPT: Retrofit by lazy {
Retrofit.Builder().baseUrl(BuildConfig.CHAT_GPT_BASE_URL).client(client)
val retrofitForOpenAiService: Retrofit by lazy {
Retrofit.Builder().baseUrl(BuildConfig.OPEN_AI_BASE_URL).client(client)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())).build()
}

inline fun <reified T> create(forWhichServer: Server): T =
when (forWhichServer) {
Server.GrowTreeServer -> retrofitForGrowTreeServer.create(T::class.java)
Server.ChatGPT -> retrofitForChatGPT.create(T::class.java)
Server.ChatGPT -> retrofitForOpenAiService.create(T::class.java)
}
}

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins {
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.ktlint) apply false

kotlin("jvm") version "1.9.23"
kotlin("plugin.serialization") version "1.9.23"
kotlin("jvm") version "1.9.23" apply false
kotlin("plugin.serialization") version "1.9.23" apply false
}

buildscript {
Expand Down

0 comments on commit e3aba7b

Please sign in to comment.