-
Notifications
You must be signed in to change notification settings - Fork 1
Data & Network 모듈 생성 #12
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
857eb3d
feat: core:data 모듈 추가
HamBeomJoon ef77abf
feat: core:network 모듈 생성 및 네트워크 라이브러리 설정
HamBeomJoon 335d4f3
feat: 네트워크 모듈 기본 설정 및 유틸리티 구현
HamBeomJoon e6b6ec9
feat: 네트워크 모듈 구조 개선 및 Ktorfit 컨버터 도입
HamBeomJoon a1a1ba3
refactor: ApiResponse 구조 개선 및 예외 처리 로직 수정
HamBeomJoon 8c7694d
feat: ApiResponseConverterFactory 내 에러 로깅 추가
HamBeomJoon 1c55e8b
refactor: ApiResponse.Failure.NetworkError 구조 변경 및 예외 전달 처리
HamBeomJoon 47a3623
chore: NetworkModule JSON prettyPrint 비활성화
HamBeomJoon 1f3d7c3
feat: 빌드 타입별 BASE_URL 설정 및 localProperty 확장 함수 추가
HamBeomJoon b740bdf
build: Hilt 컨벤션 플러그인 내 kotlin-metadata-jvm 의존성 추가
HamBeomJoon b7332d1
refactor: local.properties 로드 로직 개선 및 예외 처리 추가
HamBeomJoon edaabcf
refactor: local.properties 로드 방식 개선 및 BASE_URL 설정 로직 수정
HamBeomJoon 66fc4d5
refactor: 사용하지 않는 로거 및 임포트 제거
HamBeomJoon f19c3b3
refactor: build-logic 내부 구현을 위한 패키지 구조 변경
moondev03 1bef85c
refactor(network): ApiResponseConverterFactory 로직 개선
moondev03 35377fb
refactor(network): ApiResponseConverterFactory 로직 개선
moondev03 2afbabe
feat(detekt): TooGenericExceptionCaught 비활성화
moondev03 d75301a
feat: BuildConfig BASE_URL 설정 방식 변경
moondev03 6813338
build: local.properties 접근 방식 개선 및 BASE_URL 설정 로직 수정
HamBeomJoon 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 hidden or 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,14 +1,21 @@ | ||
| plugins { | ||
| alias(libs.plugins.prezel.android.application) | ||
| alias(libs.plugins.prezel.android.application.compose) | ||
| alias(libs.plugins.prezel.hilt) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.team.prezel" | ||
|
|
||
| buildFeatures { | ||
| buildConfig = true | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(projects.core.data) | ||
|
|
||
| implementation(libs.androidx.activity.ktx) | ||
| implementation(libs.androidx.core.ktx) | ||
| implementation(libs.androidx.lifecycle.runtime.ktx) | ||
| implementation(libs.timber) | ||
| } |
This file contains hidden or 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
15 changes: 15 additions & 0 deletions
15
Prezel/app/src/main/java/com/team/prezel/PrezelApplication.kt
This file contains hidden or 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,15 @@ | ||
| package com.team.prezel | ||
|
|
||
| import android.app.Application | ||
| import dagger.hilt.android.HiltAndroidApp | ||
| import timber.log.Timber | ||
|
|
||
| @HiltAndroidApp | ||
| class PrezelApplication : Application() { | ||
| override fun onCreate() { | ||
| super.onCreate() | ||
| if (BuildConfig.DEBUG) { | ||
| Timber.plant(Timber.DebugTree()) | ||
| } | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...ention/src/main/java/com/team/prezel/buildlogic/convention/external/LocalPropertiesExt.kt
This file contains hidden or 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,28 @@ | ||
| package com.team.prezel.buildlogic.convention.external | ||
|
|
||
| import org.gradle.api.Project | ||
| import org.gradle.api.provider.Provider | ||
| import java.io.StringReader | ||
| import java.util.Properties | ||
|
|
||
| fun Project.localProperty(key: String): Provider<String> { | ||
| val localPropertiesFile = isolated.rootProject.projectDirectory.file("local.properties") | ||
|
|
||
| return providers.provider { | ||
| val file = localPropertiesFile.asFile | ||
| if (!file.exists()) { | ||
| logger.warn("local.properties not found") | ||
| return@provider null | ||
| } | ||
|
|
||
| val properties = Properties() | ||
| properties.load(StringReader(file.readText())) | ||
| val value = properties.getProperty(key) | ||
|
|
||
| if (value == null) { | ||
| logger.warn("Key '$key' not found in local.properties") | ||
| } | ||
|
|
||
| value | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...l/buildlogic/convention/AndroidCompose.kt → ...gic/convention/internal/AndroidCompose.kt
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...el/buildlogic/convention/KotlinAndroid.kt → ...ogic/convention/internal/KotlinAndroid.kt
This file contains hidden or 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
4 changes: 2 additions & 2 deletions
4
...uildlogic/convention/ProjectExtensions.kt → .../convention/internal/ProjectExtensions.kt
This file contains hidden or 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,9 +1,9 @@ | ||
| package com.team.prezel.buildlogic.convention | ||
| package com.team.prezel.buildlogic.convention.internal | ||
|
|
||
| import org.gradle.api.Project | ||
| import org.gradle.api.artifacts.VersionCatalog | ||
| import org.gradle.api.artifacts.VersionCatalogsExtension | ||
| import org.gradle.kotlin.dsl.getByType | ||
|
|
||
| val Project.libs | ||
| internal val Project.libs | ||
| get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs") |
2 changes: 1 addition & 1 deletion
2
...com/team/prezel/buildlogic/convention/plugin/AndroidApplicationComposeConventionPlugin.kt
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...n/java/com/team/prezel/buildlogic/convention/plugin/AndroidApplicationConventionPlugin.kt
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...n/java/com/team/prezel/buildlogic/convention/plugin/AndroidFeatureImplConventionPlugin.kt
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...ava/com/team/prezel/buildlogic/convention/plugin/AndroidLibraryComposeConventionPlugin.kt
This file contains hidden or 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
4 changes: 2 additions & 2 deletions
4
.../main/java/com/team/prezel/buildlogic/convention/plugin/AndroidLibraryConventionPlugin.kt
This file contains hidden or 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 hidden or 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
4 changes: 2 additions & 2 deletions
4
.../src/main/java/com/team/prezel/buildlogic/convention/plugin/JvmLibraryConventionPlugin.kt
This file contains hidden or 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 hidden or 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 @@ | ||
| /build |
This file contains hidden or 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,14 @@ | ||
| plugins { | ||
| alias(libs.plugins.prezel.android.library) | ||
| alias(libs.plugins.prezel.hilt) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.team.prezel.core.data" | ||
| testOptions.unitTests.isIncludeAndroidResources = true | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(projects.core.network) | ||
| implementation(libs.kotlinx.coroutines.core) | ||
| } | ||
Empty file.
This file contains hidden or 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,21 @@ | ||
| # Add project specific ProGuard rules here. | ||
| # You can control the set of applied configuration files using the | ||
| # proguardFiles setting in build.gradle. | ||
| # | ||
| # For more details, see | ||
| # http://developer.android.com/guide/developing/tools/proguard.html | ||
|
|
||
| # If your project uses WebView with JS, uncomment the following | ||
| # and specify the fully qualified class name to the JavaScript interface | ||
| # class: | ||
| #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| # public *; | ||
| #} | ||
|
|
||
| # Uncomment this to preserve the line number information for | ||
| # debugging stack traces. | ||
| #-keepattributes SourceFile,LineNumberTable | ||
|
|
||
| # If you keep the line number information, uncomment this to | ||
| # hide the original source file name. | ||
| #-renamesourcefileattribute SourceFile |
Empty file.
This file contains hidden or 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,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest> | ||
|
|
||
| </manifest> |
9 changes: 9 additions & 0 deletions
9
Prezel/core/data/src/main/java/com/team/prezel/core/data/RepositoryModule.kt
This file contains hidden or 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,9 @@ | ||
| package com.team.prezel.core.data | ||
|
|
||
| import dagger.Module | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| abstract class RepositoryModule |
Empty file.
This file contains hidden or 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 @@ | ||
| /build |
This file contains hidden or 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,47 @@ | ||
| import com.android.build.api.variant.BuildConfigField | ||
| import com.team.prezel.buildlogic.convention.external.localProperty | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.prezel.android.library) | ||
| alias(libs.plugins.prezel.hilt) | ||
| alias(libs.plugins.kotlinx.serialization) | ||
| } | ||
|
|
||
| android { | ||
| buildFeatures { | ||
| buildConfig = true | ||
| } | ||
|
|
||
| namespace = "com.team.prezel.core.network" | ||
| testOptions.unitTests.isIncludeAndroidResources = true | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(libs.ktor.client.core) | ||
| implementation(libs.ktor.client.okhttp) | ||
| implementation(libs.ktor.client.content.negotiation) | ||
| implementation(libs.ktor.serialization.kotlinx.json) | ||
| implementation(libs.ktor.client.logging) | ||
| implementation(libs.kotlinx.serialization.json) | ||
| implementation(libs.timber) | ||
|
|
||
| implementation(libs.ktorfit.lib) | ||
| ksp(libs.ktorfit.ksp) | ||
|
|
||
| testImplementation(libs.kotlinx.coroutines.test) | ||
| } | ||
|
|
||
| androidComponents { | ||
| onVariants { variant -> | ||
| val buildType = variant.buildType ?: return@onVariants | ||
| val buildConfigFields = variant.buildConfigFields ?: return@onVariants | ||
| val baseUrlKey = "${buildType.uppercase()}_BASE_URL" | ||
|
|
||
| buildConfigFields.put( | ||
| "BASE_URL", | ||
| localProperty(baseUrlKey).map { value -> | ||
| BuildConfigField("String", "\"$value\"", null) | ||
| }, | ||
| ) | ||
|
moondev03 marked this conversation as resolved.
|
||
| } | ||
| } | ||
Empty file.
This file contains hidden or 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,21 @@ | ||
| # Add project specific ProGuard rules here. | ||
| # You can control the set of applied configuration files using the | ||
| # proguardFiles setting in build.gradle. | ||
| # | ||
| # For more details, see | ||
| # http://developer.android.com/guide/developing/tools/proguard.html | ||
|
|
||
| # If your project uses WebView with JS, uncomment the following | ||
| # and specify the fully qualified class name to the JavaScript interface | ||
| # class: | ||
| #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| # public *; | ||
| #} | ||
|
|
||
| # Uncomment this to preserve the line number information for | ||
| # debugging stack traces. | ||
| #-keepattributes SourceFile,LineNumberTable | ||
|
|
||
| # If you keep the line number information, uncomment this to | ||
| # hide the original source file name. | ||
| #-renamesourcefileattribute SourceFile |
Empty file.
This file contains hidden or 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,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
|
|
||
| </manifest> |
70 changes: 70 additions & 0 deletions
70
...el/core/network/src/main/java/com/team/prezel/core/network/ApiResponseConverterFactory.kt
This file contains hidden or 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,70 @@ | ||
| package com.team.prezel.core.network | ||
|
|
||
| import com.team.prezel.core.network.model.ApiResponse | ||
| import de.jensklingenberg.ktorfit.Ktorfit | ||
| import de.jensklingenberg.ktorfit.converter.Converter | ||
| import de.jensklingenberg.ktorfit.converter.KtorfitResult | ||
| import de.jensklingenberg.ktorfit.converter.TypeData | ||
| import io.ktor.client.call.body | ||
| import io.ktor.client.plugins.ResponseException | ||
| import io.ktor.client.statement.HttpResponse | ||
| import io.ktor.util.reflect.TypeInfo | ||
| import timber.log.Timber | ||
| import java.io.IOException | ||
| import kotlin.coroutines.cancellation.CancellationException | ||
|
|
||
| class ApiResponseConverterFactory : Converter.Factory { | ||
| override fun suspendResponseConverter( | ||
| typeData: TypeData, | ||
| ktorfit: Ktorfit, | ||
| ): Converter.SuspendResponseConverter<HttpResponse, *>? { | ||
| if (typeData.typeInfo.type != ApiResponse::class) return null | ||
| val bodyTypeInfo = typeData.typeArgs.firstOrNull()?.typeInfo ?: return null | ||
|
|
||
| return object : Converter.SuspendResponseConverter<HttpResponse, ApiResponse<Any>> { | ||
| override suspend fun convert(result: KtorfitResult): ApiResponse<Any> = | ||
| when (result) { | ||
| is KtorfitResult.Success -> parseSuccess(result.response, bodyTypeInfo) | ||
| is KtorfitResult.Failure -> mapFailure(result.throwable) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private suspend fun parseSuccess( | ||
| response: HttpResponse, | ||
| bodyTypeInfo: TypeInfo, | ||
| ): ApiResponse<Any> = | ||
| try { | ||
| val body = response.body<Any>(bodyTypeInfo) | ||
| ApiResponse.Success(body) | ||
| } catch (t: Throwable) { | ||
| t.rethrowIfCancellation() | ||
| Timber.e(t, "Response parsing failed") | ||
| ApiResponse.Failure.NetworkError(t) | ||
| } | ||
|
|
||
| private fun mapFailure(t: Throwable): ApiResponse<Any> { | ||
| t.rethrowIfCancellation() | ||
|
|
||
| return when (t) { | ||
| is IOException -> { | ||
| Timber.e(t, "Network error") | ||
| ApiResponse.Failure.NetworkError(t) | ||
| } | ||
|
|
||
| is ResponseException -> { | ||
| Timber.e(t, "HTTP error ${t.response.status.value}") | ||
| ApiResponse.Failure.HttpError(t) | ||
| } | ||
|
|
||
| else -> { | ||
| Timber.e(t, "Unknown error") | ||
| ApiResponse.Failure.NetworkError(t) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun Throwable.rethrowIfCancellation() { | ||
| if (this is CancellationException) throw this | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.