File tree Expand file tree Collapse file tree 3 files changed +29
-12
lines changed
src/main/java/woowacourse/shopping/data Expand file tree Collapse file tree 3 files changed +29
-12
lines changed Original file line number Diff line number Diff line change 1
1
plugins {
2
+ id(" kotlin-kapt" )
2
3
alias(libs.plugins.android.application)
3
4
alias(libs.plugins.android.junit5)
4
5
alias(libs.plugins.kotlin.android)
5
- id(" kotlin-kapt" )
6
6
alias(libs.plugins.serialization)
7
7
}
8
8
@@ -23,12 +23,16 @@ android {
23
23
}
24
24
25
25
buildTypes {
26
+ debug {
27
+ buildConfigField(" boolean" , " DEBUG" , " true" )
28
+ }
26
29
release {
27
30
isMinifyEnabled = false
28
31
proguardFiles(
29
32
getDefaultProguardFile(" proguard-android-optimize.txt" ),
30
33
" proguard-rules.pro" ,
31
34
)
35
+ buildConfigField(" boolean" , " DEBUG" , " false" )
32
36
}
33
37
}
34
38
compileOptions {
@@ -46,12 +50,13 @@ android {
46
50
}
47
51
buildFeatures {
48
52
dataBinding = true
53
+ buildConfig = true
49
54
}
50
55
}
51
56
52
57
dependencies {
53
- implementation(libs.androidx.activity)
54
58
kapt(libs.androidx.room.compiler)
59
+ implementation(libs.androidx.activity)
55
60
implementation(libs.androidx.activity.ktx)
56
61
implementation(libs.androidx.appcompat)
57
62
implementation(libs.androidx.constraintlayout)
Original file line number Diff line number Diff line change @@ -6,18 +6,16 @@ import okhttp3.MediaType.Companion.toMediaType
6
6
import okhttp3.OkHttpClient
7
7
import okhttp3.logging.HttpLoggingInterceptor
8
8
import retrofit2.Retrofit
9
+ import woowacourse.shopping.BuildConfig
9
10
import woowacourse.shopping.data.cart.service.CartService
10
11
import woowacourse.shopping.data.product.service.ProductService
11
12
12
13
object API {
13
14
private val client: OkHttpClient =
14
15
OkHttpClient
15
16
.Builder ()
16
- .addInterceptor(
17
- HttpLoggingInterceptor ().apply {
18
- level = HttpLoggingInterceptor .Level .BODY
19
- },
20
- ).build()
17
+ .addHttpLoggingInterceptor()
18
+ .build()
21
19
22
20
private val retrofit =
23
21
Retrofit
@@ -29,4 +27,12 @@ object API {
29
27
30
28
val productService: ProductService = retrofit.create(ProductService ::class .java)
31
29
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
+ )
32
38
}
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import okhttp3.Request
7
7
import okhttp3.RequestBody.Companion.toRequestBody
8
8
import okhttp3.Response
9
9
import okhttp3.logging.HttpLoggingInterceptor
10
+ import woowacourse.shopping.BuildConfig
10
11
import woowacourse.shopping.data.cart.dto.CartItemRequest
11
12
import woowacourse.shopping.data.cart.dto.CartQuantityResponse
12
13
import woowacourse.shopping.data.cart.dto.CartResponse
@@ -111,11 +112,8 @@ class ProductsHttpClient(
111
112
private val client: OkHttpClient =
112
113
OkHttpClient
113
114
.Builder ()
114
- .addInterceptor(
115
- HttpLoggingInterceptor ().apply {
116
- level = HttpLoggingInterceptor .Level .BODY
117
- },
118
- ).build()
115
+ .addHttpLoggingInterceptor()
116
+ .build()
119
117
120
118
private fun http (
121
119
httpMethod : HttpMethod ,
@@ -146,6 +144,14 @@ class ProductsHttpClient(
146
144
}
147
145
}
148
146
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
+
149
155
companion object {
150
156
private const val PATH_CART_ITEMS = " /cart-items"
151
157
private const val MEDIA_TYPE_JSON = " application/json"
You can’t perform that action at this time.
0 commit comments