-
Notifications
You must be signed in to change notification settings - Fork 3
[API] api 연결 세팅 #64
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
[API] api 연결 세팅 #64
Changes from all commits
297d017
2c37a09
fea07fe
c761e66
870b7cc
06a3cde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,16 @@ | ||
| import org.gradle.kotlin.dsl.implementation | ||
| import java.util.Properties | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.android.application) | ||
| alias(libs.plugins.kotlin.android) | ||
| alias(libs.plugins.kotlin.compose) | ||
| alias(libs.plugins.kotlin.serialization) | ||
| id("com.google.dagger.hilt.android") | ||
| kotlin("kapt") | ||
| } | ||
|
|
||
| val properties = Properties().apply { | ||
| load(project.rootProject.file("local.properties").inputStream()) | ||
| } | ||
|
|
||
| android { | ||
|
|
@@ -19,6 +25,8 @@ android { | |
| versionName = "1.0" | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
|
|
||
|
Collaborator
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. 이 부분은 어떤 뜻인가요?
Member
Author
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. local properties에서 BASE_URL을 가져와서 build config에 상수화하는 역할입니닷 ! base url을 드러내지 않기 위해서 이런 코드를 작성했습니닷 |
||
| buildConfigField("String", "BASE_URL", "\"${properties["BASE_URL"]}\"") | ||
| } | ||
|
|
||
| buildTypes { | ||
|
|
@@ -39,6 +47,7 @@ android { | |
| } | ||
| buildFeatures { | ||
| compose = true | ||
| buildConfig = true | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -67,4 +76,22 @@ dependencies { | |
| androidTestImplementation(libs.androidx.ui.test.junit4) | ||
| debugImplementation(libs.androidx.ui.tooling) | ||
| debugImplementation(libs.androidx.ui.test.manifest) | ||
|
|
||
| // Hilt | ||
| implementation(libs.hilt.android) | ||
| kapt(libs.hilt.android.compiler) | ||
| implementation(libs.androidx.hilt.navigation.compose) | ||
|
|
||
| // Retrofit | ||
| implementation(libs.retrofit) | ||
| implementation(libs.converter.gson) | ||
| implementation(libs.retrofit.kotlin.serialization.converter) | ||
|
|
||
| // OkHttp | ||
| implementation(libs.okhttp) | ||
| implementation(libs.logging.interceptor) | ||
| } | ||
|
Comment on lines
+81
to
+93
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. 💡 Verification agent 🧩 Analysis chain의존성 버전을 확인하세요. Hilt, Retrofit, OkHttp 라이브러리들의 버전 호환성과 최신 보안 패치 적용 여부를 확인하는 것이 좋습니다. 라이브러리 최신 버전을 확인해주세요: 🌐 Web query: 💡 Result: 안녕하세요! Dagger Hilt, Retrofit, OkHttp의 최신 안정 버전과 보안 권고사항에 대해 알려드리겠습니다. 최신 안정 버전:
이러한 버전들은 각 라이브러리의 공식 문서나 GitHub 저장소에서 확인하실 수 있습니다. 보안 권고사항:
이러한 권고사항을 따르면 앱의 보안을 강화할 수 있습니다. 의존성 버전 업데이트 및 보안 강화 권고 아래 라이브러리들이 최신 안정 버전인지 확인하고, 필요 시 버전을 상향 조정해주세요. 또한 보안 권고사항을 참고해 네트워크 통신 설정을 강화하시기 바랍니다.
보안 권고사항
🤖 Prompt for AI Agents |
||
|
|
||
| kapt { | ||
| correctErrorTypes = true | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.texthip.thip | ||
|
|
||
| import android.app.Application | ||
| import dagger.hilt.android.HiltAndroidApp | ||
|
|
||
| @HiltAndroidApp | ||
| class ThipApplication : Application() |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||||||||||||||||||||
| package com.texthip.thip.data.di | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||||||||||||||||||||||||||
| import com.texthip.thip.BuildConfig | ||||||||||||||||||||||||||
| import dagger.Module | ||||||||||||||||||||||||||
| import dagger.Provides | ||||||||||||||||||||||||||
| import dagger.hilt.InstallIn | ||||||||||||||||||||||||||
| import dagger.hilt.components.SingletonComponent | ||||||||||||||||||||||||||
| import kotlinx.serialization.ExperimentalSerializationApi | ||||||||||||||||||||||||||
| import kotlinx.serialization.json.Json | ||||||||||||||||||||||||||
| import okhttp3.MediaType.Companion.toMediaType | ||||||||||||||||||||||||||
| import okhttp3.OkHttpClient | ||||||||||||||||||||||||||
| import okhttp3.logging.HttpLoggingInterceptor | ||||||||||||||||||||||||||
| import retrofit2.Retrofit | ||||||||||||||||||||||||||
| import java.util.concurrent.TimeUnit | ||||||||||||||||||||||||||
| import javax.inject.Singleton | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Module | ||||||||||||||||||||||||||
| @InstallIn(SingletonComponent::class) | ||||||||||||||||||||||||||
| object NetworkModule { | ||||||||||||||||||||||||||
| @OptIn(ExperimentalSerializationApi::class) | ||||||||||||||||||||||||||
| @Provides | ||||||||||||||||||||||||||
| @Singleton | ||||||||||||||||||||||||||
| fun provideJson(): Json = | ||||||||||||||||||||||||||
| Json { | ||||||||||||||||||||||||||
| isLenient = true // 유연한 JSON 구분 허용 | ||||||||||||||||||||||||||
| prettyPrint = true // 출력 JSON 을 예쁘게 들여쓰기해서 가독성을 높임 | ||||||||||||||||||||||||||
| encodeDefaults = true // 파라미터의 기본값(default) 을 JSON 으로 인코딩 | ||||||||||||||||||||||||||
| explicitNulls = false // null 값을 명시적으로 표시하지 않음 | ||||||||||||||||||||||||||
| ignoreUnknownKeys = true // JSON 에 정의하지 않은 키가 있어도 무시하고 파싱 | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Provides | ||||||||||||||||||||||||||
| @Singleton | ||||||||||||||||||||||||||
| fun providesOkHttpClient( | ||||||||||||||||||||||||||
| loggingInterceptor: HttpLoggingInterceptor, | ||||||||||||||||||||||||||
| // authInterceptor: AuthInterceptor, | ||||||||||||||||||||||||||
| // authAuthenticator: TokenAuthenticator | ||||||||||||||||||||||||||
| ): OkHttpClient = | ||||||||||||||||||||||||||
| OkHttpClient.Builder().apply { | ||||||||||||||||||||||||||
| connectTimeout(10, TimeUnit.SECONDS) | ||||||||||||||||||||||||||
| writeTimeout(10, TimeUnit.SECONDS) | ||||||||||||||||||||||||||
| readTimeout(10, TimeUnit.SECONDS) | ||||||||||||||||||||||||||
| addInterceptor(loggingInterceptor) | ||||||||||||||||||||||||||
| // addInterceptor(authInterceptor) | ||||||||||||||||||||||||||
| // authenticator(authAuthenticator) | ||||||||||||||||||||||||||
| }.build() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Provides | ||||||||||||||||||||||||||
| @Singleton | ||||||||||||||||||||||||||
| fun providesLoggingInterceptor(): HttpLoggingInterceptor = | ||||||||||||||||||||||||||
| HttpLoggingInterceptor().apply { | ||||||||||||||||||||||||||
| level = HttpLoggingInterceptor.Level.BODY | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+51
to
+54
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. 🛠️ Refactor suggestion 로깅 레벨을 환경에 따라 조정하세요. 현재 BuildConfig를 활용해 디버그/릴리즈 환경에 따라 로깅 레벨을 조정하세요: fun providesLoggingInterceptor(): HttpLoggingInterceptor =
HttpLoggingInterceptor().apply {
- level = HttpLoggingInterceptor.Level.BODY
+ level = if (BuildConfig.DEBUG) {
+ HttpLoggingInterceptor.Level.BODY
+ } else {
+ HttpLoggingInterceptor.Level.NONE
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Provides | ||||||||||||||||||||||||||
| @Singleton | ||||||||||||||||||||||||||
| fun providesRetrofit( | ||||||||||||||||||||||||||
| json: Json, | ||||||||||||||||||||||||||
| okHttpClient: OkHttpClient | ||||||||||||||||||||||||||
| ): Retrofit = | ||||||||||||||||||||||||||
| Retrofit.Builder() | ||||||||||||||||||||||||||
| .baseUrl(BuildConfig.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. 💡 Verification agent 🧩 Analysis chainBASE_URL 설정을 검증하세요.
다음 스크립트로 BASE_URL 설정을 확인해주세요: 🏁 Script executed: #!/bin/bash
# BuildConfig 파일에서 BASE_URL 확인
fd -t f -e java "BuildConfig" --exec grep -l "BASE_URL" {} \;Length of output: 62 🏁 Script executed: #!/bin/bash
# 전체 코드베이스에서 BASE_URL 정의 및 사용 위치 검색
rg -n 'BASE_URL'
# build.gradle(.kts) 파일에서 buildConfigField BASE_URL 정의 확인
rg -n 'buildConfigField.*BASE_URL' -g '*.gradle' -g '*.gradle.kts'Length of output: 399 🏁 Script executed: #!/bin/bash
# gradle.properties 및 local.properties에서 BASE_URL 정의 여부 확인
rg -n 'BASE_URL' -g '*.properties'Length of output: 34 BASE_URL 프로퍼티 정의 누락 확인 및 설정 필요 app/build.gradle.kts (29행)에서 buildConfigField("String", "BASE_URL", "\"${properties["BASE_URL"]}\"")로 해결 방안:
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| .addConverterFactory( | ||||||||||||||||||||||||||
| json.asConverterFactory(requireNotNull("application/json".toMediaType())) | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| .client(okHttpClient) | ||||||||||||||||||||||||||
| .build() | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.texthip.thip.data.di | ||
|
|
||
| import dagger.Module | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object ServiceModule { | ||
| // @Provides | ||
| // @Singleton | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.texthip.thip.data.model.base | ||
|
|
||
| fun <T> BaseResponse<T>.handleBaseResponse(): Result<T?> { | ||
| return if (isSuccess) { | ||
| Result.success(this.response) | ||
| } else { | ||
| Result.failure( | ||
| ThipApiFailureException( | ||
| code = this.code, | ||
| message = this.message | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| data class ThipApiFailureException( | ||
| val code: Int, | ||
| override val message: String | ||
| ) : Throwable() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.texthip.thip.data.model.base | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class BaseResponse<T>( | ||
| @SerialName("isSuccess") val isSuccess: Boolean, | ||
| @SerialName("code") val code: Int, | ||
| @SerialName("message") val message: String, | ||
| @SerialName("data") val response: T? = null, | ||
| ) |
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.
💡 Verification agent
🧩 Analysis chain
local.properties 파일 존재 여부를 검증하세요.
local.properties파일이 존재하지 않을 경우 빌드가 실패할 수 있습니다.다음 스크립트로 파일 존재 여부와 BASE_URL 설정을 확인해주세요:
🏁 Script executed:
Length of output: 178
local.properties 파일 누락 및 예시 파일(example) 추가 필요
현재 루트 디렉토리에
local.properties파일이 없으며,.gitignore에/local.properties와local.properties가 모두 등록되어 있습니다.이대로라면 Gradle에서
project.rootProject.file("local.properties")를 로드할 때 빌드가 실패합니다.해야 할 작업:
local.properties.example(또는local.properties.template) 파일을 추가하고, README 등에 실제local.properties생성 및 BASE_URL 설정 방법을 문서화하세요.app/build.gradle.kts에서 파일이 없을 경우 기본값을 설정하거나 로드 구문을 감싸서 빌드 실패를 방지하는 처리(.exists()체크 등)를 추가하세요.대략적인 코드 예시:
val properties = Properties().apply { - load(project.rootProject.file("local.properties").inputStream()) + val propFile = project.rootProject.file("local.properties") + if (propFile.exists()) { + load(propFile.inputStream()) + } else { + logger.warn("local.properties not found: using default BASE_URL") + setProperty("BASE_URL", "https://default.example.com") + } }🤖 Prompt for AI Agents