-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retrofit 설정 #13
Merged
Merged
Retrofit 설정 #13
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3347ce3
#11 retrofit & okhttp toml 추가
laco-dev cddb03c
#11 data 모듈 Retrofit, Okhttp 의존성 추가
laco-dev 3643946
#11 data모듈을 안드로이드 모듈로 변경
laco-dev b33ca07
#11 ApiService DI 모듈 추가
laco-dev 2f2166c
#11 kotlin-serialization 플러그인 및 의존성 추가
laco-dev e44690f
#11 KotlinSerialization ConverterFactory 추가
laco-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
40 changes: 40 additions & 0 deletions
40
core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kotlinx serialization은 의존성만 추가하셨는데 ConverterFactory 등록도 같이 해주시면 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.addConverterFactory(json.asConverterFactory("application/json".toMediaType())) | ||
.client(okHttpClient) | ||
.build() | ||
|
||
@Provides | ||
@Singleton | ||
fun provideJson(): Json = Json { | ||
ignoreUnknownKeys = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
왜 Diff로 잡혔을까요? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네트워크 외에도 로컬 관련 로직이 포함될 것 같아서 kotlin --> android 모듈로 변경되었습니다.