Skip to content

Commit 1063871

Browse files
refactor: add branch for debug
1 parent 9eca1f9 commit 1063871

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

app/build.gradle.kts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
2+
id("kotlin-kapt")
23
alias(libs.plugins.android.application)
34
alias(libs.plugins.android.junit5)
45
alias(libs.plugins.kotlin.android)
5-
id("kotlin-kapt")
66
alias(libs.plugins.serialization)
77
}
88

@@ -23,12 +23,16 @@ android {
2323
}
2424

2525
buildTypes {
26+
debug {
27+
buildConfigField("boolean", "DEBUG", "true")
28+
}
2629
release {
2730
isMinifyEnabled = false
2831
proguardFiles(
2932
getDefaultProguardFile("proguard-android-optimize.txt"),
3033
"proguard-rules.pro",
3134
)
35+
buildConfigField("boolean", "DEBUG", "false")
3236
}
3337
}
3438
compileOptions {
@@ -46,12 +50,13 @@ android {
4650
}
4751
buildFeatures {
4852
dataBinding = true
53+
buildConfig = true
4954
}
5055
}
5156

5257
dependencies {
53-
implementation(libs.androidx.activity)
5458
kapt(libs.androidx.room.compiler)
59+
implementation(libs.androidx.activity)
5560
implementation(libs.androidx.activity.ktx)
5661
implementation(libs.androidx.appcompat)
5762
implementation(libs.androidx.constraintlayout)

app/src/main/java/woowacourse/shopping/data/API.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import okhttp3.MediaType.Companion.toMediaType
66
import okhttp3.OkHttpClient
77
import okhttp3.logging.HttpLoggingInterceptor
88
import retrofit2.Retrofit
9+
import woowacourse.shopping.BuildConfig
910
import woowacourse.shopping.data.cart.service.CartService
1011
import woowacourse.shopping.data.product.service.ProductService
1112

1213
object API {
1314
private val client: OkHttpClient =
1415
OkHttpClient
1516
.Builder()
16-
.addInterceptor(
17-
HttpLoggingInterceptor().apply {
18-
level = HttpLoggingInterceptor.Level.BODY
19-
},
20-
).build()
17+
.addHttpLoggingInterceptor()
18+
.build()
2119

2220
private val retrofit =
2321
Retrofit
@@ -29,4 +27,12 @@ object API {
2927

3028
val productService: ProductService = retrofit.create(ProductService::class.java)
3129
val cartService: CartService = retrofit.create(CartService::class.java)
30+
31+
private fun OkHttpClient.Builder.addHttpLoggingInterceptor() =
32+
addInterceptor(
33+
HttpLoggingInterceptor().apply {
34+
level =
35+
if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
36+
},
37+
)
3238
}

app/src/main/java/woowacourse/shopping/data/ProductsHttpClient.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import okhttp3.Request
77
import okhttp3.RequestBody.Companion.toRequestBody
88
import okhttp3.Response
99
import okhttp3.logging.HttpLoggingInterceptor
10+
import woowacourse.shopping.BuildConfig
1011
import woowacourse.shopping.data.cart.dto.CartItemRequest
1112
import woowacourse.shopping.data.cart.dto.CartQuantityResponse
1213
import woowacourse.shopping.data.cart.dto.CartResponse
@@ -111,11 +112,8 @@ class ProductsHttpClient(
111112
private val client: OkHttpClient =
112113
OkHttpClient
113114
.Builder()
114-
.addInterceptor(
115-
HttpLoggingInterceptor().apply {
116-
level = HttpLoggingInterceptor.Level.BODY
117-
},
118-
).build()
115+
.addHttpLoggingInterceptor()
116+
.build()
119117

120118
private fun http(
121119
httpMethod: HttpMethod,
@@ -146,6 +144,14 @@ class ProductsHttpClient(
146144
}
147145
}
148146

147+
private fun OkHttpClient.Builder.addHttpLoggingInterceptor() =
148+
addInterceptor(
149+
HttpLoggingInterceptor().apply {
150+
level =
151+
if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
152+
},
153+
)
154+
149155
companion object {
150156
private const val PATH_CART_ITEMS = "/cart-items"
151157
private const val MEDIA_TYPE_JSON = "application/json"

0 commit comments

Comments
 (0)