From 2a23faa1bc2189742996803f4cdda1cbf2a8b2e7 Mon Sep 17 00:00:00 2001 From: Dongmin Date: Wed, 10 Jan 2024 05:12:39 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[CHORE/#55]=20retrofit=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/going/going/di/DataStoreModule.kt | 2 +- .../com/going/going/di/RepositoryModule.kt | 4 +- .../java/com/going/going/di/RetrofitModule.kt | 38 +++++++++++++++++-- .../java/com/going/going/di/ServiceModule.kt | 5 ++- .../data/dto/request/SignInRequestDto.kt | 3 +- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/going/going/di/DataStoreModule.kt b/app/src/main/java/com/going/going/di/DataStoreModule.kt index 52a36091..6c342023 100644 --- a/app/src/main/java/com/going/going/di/DataStoreModule.kt +++ b/app/src/main/java/com/going/going/di/DataStoreModule.kt @@ -2,8 +2,8 @@ package com.going.going.di import android.content.Context import android.content.SharedPreferences -import com.going.data.local.GoingDataStoreImpl import com.going.data.local.GoingDataStore +import com.going.data.local.GoingDataStoreImpl import dagger.Module import dagger.Provides import dagger.hilt.InstallIn diff --git a/app/src/main/java/com/going/going/di/RepositoryModule.kt b/app/src/main/java/com/going/going/di/RepositoryModule.kt index cad8a8ac..d8fcf24a 100644 --- a/app/src/main/java/com/going/going/di/RepositoryModule.kt +++ b/app/src/main/java/com/going/going/di/RepositoryModule.kt @@ -1,11 +1,11 @@ package com.going.going.di -import com.going.data.repositoryImpl.TokenRepositoryImpl import com.going.data.repositoryImpl.AuthRepositoryImpl import com.going.data.repositoryImpl.MockRepositoryImpl -import com.going.domain.repository.TokenRepository +import com.going.data.repositoryImpl.TokenRepositoryImpl import com.going.domain.repository.AuthRepository import com.going.domain.repository.MockRepository +import com.going.domain.repository.TokenRepository import dagger.Module import dagger.Provides import dagger.hilt.InstallIn diff --git a/app/src/main/java/com/going/going/di/RetrofitModule.kt b/app/src/main/java/com/going/going/di/RetrofitModule.kt index 3cb742fe..03570722 100644 --- a/app/src/main/java/com/going/going/di/RetrofitModule.kt +++ b/app/src/main/java/com/going/going/di/RetrofitModule.kt @@ -1,6 +1,8 @@ package com.going.going.di import com.going.going.BuildConfig.BASE_URL +import com.going.going.di.qualifier.JWT +import com.going.going.di.qualifier.KAKAO import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import dagger.Module import dagger.Provides @@ -54,7 +56,8 @@ object RetrofitModule { @Provides @Singleton - fun provideOkHttpClient( + @KAKAO + fun provideKAKAOOkHttpClient( loggingInterceptor: Interceptor, ): OkHttpClient = OkHttpClient.Builder() .addInterceptor(loggingInterceptor) @@ -62,8 +65,37 @@ object RetrofitModule { @Provides @Singleton - fun provideRetrofit( - client: OkHttpClient, + @JWT + fun provideJWTOkHttpClient( + loggingInterceptor: Interceptor, + @JWT authInterceptor: Interceptor, + ): OkHttpClient = OkHttpClient.Builder() + .addInterceptor(loggingInterceptor) + .addInterceptor(authInterceptor) + .build() + + @Provides + @Singleton + @JWT + fun provideAuthInterceptor(interceptor: AuthInterceptor): Interceptor = interceptor + + @Provides + @Singleton + @KAKAO + fun provideKAKAORetrofit( + @KAKAO client: OkHttpClient, + factory: Converter.Factory, + ): Retrofit = Retrofit.Builder() + .baseUrl(BASE_URL) + .client(client) + .addConverterFactory(factory) + .build() + + @Provides + @Singleton + @JWT + fun provideJWTRetrofit( + @JWT client: OkHttpClient, factory: Converter.Factory, ): Retrofit = Retrofit.Builder() .baseUrl(BASE_URL) diff --git a/app/src/main/java/com/going/going/di/ServiceModule.kt b/app/src/main/java/com/going/going/di/ServiceModule.kt index 1e96393d..807674da 100644 --- a/app/src/main/java/com/going/going/di/ServiceModule.kt +++ b/app/src/main/java/com/going/going/di/ServiceModule.kt @@ -2,6 +2,7 @@ package com.going.going.di import com.going.data.service.AuthService import com.going.data.service.MockService +import com.going.going.di.qualifier.KAKAO import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -15,11 +16,11 @@ object ServiceModule { @Provides @Singleton - fun provideMockService(retrofit: Retrofit): MockService = + fun provideMockService(@KAKAO retrofit: Retrofit): MockService = retrofit.create(MockService::class.java) @Provides @Singleton - fun provideLoginService(retrofit: Retrofit): AuthService = + fun provideAuthService(@KAKAO retrofit: Retrofit): AuthService = retrofit.create(AuthService::class.java) } diff --git a/data/src/main/java/com/going/data/dto/request/SignInRequestDto.kt b/data/src/main/java/com/going/data/dto/request/SignInRequestDto.kt index bd982038..7a5f50c2 100644 --- a/data/src/main/java/com/going/data/dto/request/SignInRequestDto.kt +++ b/data/src/main/java/com/going/data/dto/request/SignInRequestDto.kt @@ -1,14 +1,13 @@ package com.going.data.dto.request import com.going.domain.entity.request.RequestSignInModel -import com.going.domain.entity.request.RequestSignUpModel import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class SignInRequestDto( @SerialName("platform") - val platform: String + val platform: String, ) fun RequestSignInModel.toSignInRequestDto(): SignInRequestDto = From 9bce8b92637764e29dc7bd07000c968492e414bd Mon Sep 17 00:00:00 2001 From: Dongmin Date: Wed, 10 Jan 2024 05:12:59 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[CHORE/#55]=20Token=20Interceptor=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/going/going/di/AuthInterceptor.kt | 78 +++++++++++++++++++ .../going/di/qualifier/RetrofitQualifier.kt | 11 +++ 2 files changed, 89 insertions(+) create mode 100644 app/src/main/java/com/going/going/di/AuthInterceptor.kt create mode 100644 app/src/main/java/com/going/going/di/qualifier/RetrofitQualifier.kt diff --git a/app/src/main/java/com/going/going/di/AuthInterceptor.kt b/app/src/main/java/com/going/going/di/AuthInterceptor.kt new file mode 100644 index 00000000..fa46823d --- /dev/null +++ b/app/src/main/java/com/going/going/di/AuthInterceptor.kt @@ -0,0 +1,78 @@ +package com.going.going.di + +import android.content.Context +import com.going.data.dto.BaseResponse +import com.going.data.local.GoingDataStore +import com.going.domain.entity.response.AuthTokenModel +import com.going.going.BuildConfig.BASE_URL +import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.serialization.json.Json +import okhttp3.Interceptor +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.Response +import timber.log.Timber +import javax.inject.Inject + +class AuthInterceptor @Inject constructor( + private val json: Json, + private val dataStore: GoingDataStore, + @ApplicationContext private val context: Context, +) : Interceptor { + override fun intercept(chain: Interceptor.Chain): Response { + val originalRequest = chain.request() + val authRequest = if (dataStore.accessToken != "") { + originalRequest.newAuthBuilder().build() + } else { + originalRequest + } + val response = chain.proceed(authRequest) + + when (response.code) { + CODE_TOKEN_EXPIRED -> { + try { + val refreshTokenRequest = originalRequest.newBuilder().post("".toRequestBody()) + .url("$BASE_URL/api/v1/auth/token/issue") + .addHeader(AUTHORIZATION, dataStore.refreshToken) + .build() + val refreshTokenResponse = chain.proceed(refreshTokenRequest) + Timber.d("GET REFRESH TOKEN : $refreshTokenResponse") + + if (refreshTokenResponse.isSuccessful) { + val responseToken = json.decodeFromString( + refreshTokenResponse.body?.string().toString(), + ) as BaseResponse + + with(dataStore) { + accessToken = responseToken.data.accessToken + refreshToken = responseToken.data.refreshToken + } + refreshTokenResponse.close() + val newRequest = originalRequest.newAuthBuilder().build() + return chain.proceed(newRequest) + } + + with(dataStore) { + accessToken = "" + refreshToken = "" + } + } catch (t: Throwable) { + Timber.e(t) + with(dataStore) { + accessToken = "" + refreshToken = "" + } + } + } + } + return response + } + + private fun Request.newAuthBuilder() = + this.newBuilder().addHeader(AUTHORIZATION, "${dataStore.accessToken}") + + companion object { + private const val CODE_TOKEN_EXPIRED = 401 + private const val AUTHORIZATION = "Authorization" + } +} diff --git a/app/src/main/java/com/going/going/di/qualifier/RetrofitQualifier.kt b/app/src/main/java/com/going/going/di/qualifier/RetrofitQualifier.kt new file mode 100644 index 00000000..5fc7194f --- /dev/null +++ b/app/src/main/java/com/going/going/di/qualifier/RetrofitQualifier.kt @@ -0,0 +1,11 @@ +package com.going.going.di.qualifier + +import javax.inject.Qualifier + +@Qualifier +@Retention(AnnotationRetention.BINARY) +annotation class JWT + +@Qualifier +@Retention(AnnotationRetention.BINARY) +annotation class KAKAO From c427ee54c68482dda5d8a96470edf3061341fb31 Mon Sep 17 00:00:00 2001 From: Dongmin Date: Wed, 10 Jan 2024 06:17:31 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[FIX/#55]=20viewmodel=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tendencytest/result/TendencyTestResultActivity.kt | 2 +- .../src/main/res/layout/activity_tendency_test_result.xml | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/tendencytest/result/TendencyTestResultActivity.kt b/presentation/src/main/java/com/going/presentation/tendencytest/result/TendencyTestResultActivity.kt index c43f3b9b..d4c9c88e 100644 --- a/presentation/src/main/java/com/going/presentation/tendencytest/result/TendencyTestResultActivity.kt +++ b/presentation/src/main/java/com/going/presentation/tendencytest/result/TendencyTestResultActivity.kt @@ -26,7 +26,7 @@ class TendencyTestResultActivity : with(binding) { tvTendencyTestResultTitle.text = getString(R.string.tendency_test_result_title, "찐두릅") - viewModel?.mockTendencyResult?.apply { + viewModel.mockTendencyResult.apply { tvTendencyTestResultType.text = tendencyTitle tvTendencyTestResultSubType.text = tendencySubTitle diff --git a/presentation/src/main/res/layout/activity_tendency_test_result.xml b/presentation/src/main/res/layout/activity_tendency_test_result.xml index 7c3d4a25..4d6d9e6b 100644 --- a/presentation/src/main/res/layout/activity_tendency_test_result.xml +++ b/presentation/src/main/res/layout/activity_tendency_test_result.xml @@ -4,9 +4,6 @@ - Date: Wed, 10 Jan 2024 06:37:52 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[FEAT/#55]=20SignOut=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/going/going/di/DataSourceModule.kt | 7 +++++++ .../java/com/going/going/di/RepositoryModule.kt | 7 +++++++ .../java/com/going/going/di/ServiceModule.kt | 7 +++++++ .../going/data/datasource/SettingDataSource.kt | 7 +++++++ .../data/datasourceImpl/SettingDataSourceImpl.kt | 12 ++++++++++++ .../data/dto/response/SignOutResponseDto.kt | 16 ++++++++++++++++ .../data/repositoryImpl/SettingRepositoryImpl.kt | 14 ++++++++++++++ .../com/going/data/service/SettingService.kt | 9 +++++++++ .../going/domain/entity/response/SignOutModel.kt | 6 ++++++ .../going/domain/repository/SettingRepository.kt | 7 +++++++ 10 files changed, 92 insertions(+) create mode 100644 data/src/main/java/com/going/data/datasource/SettingDataSource.kt create mode 100644 data/src/main/java/com/going/data/datasourceImpl/SettingDataSourceImpl.kt create mode 100644 data/src/main/java/com/going/data/dto/response/SignOutResponseDto.kt create mode 100644 data/src/main/java/com/going/data/repositoryImpl/SettingRepositoryImpl.kt create mode 100644 data/src/main/java/com/going/data/service/SettingService.kt create mode 100644 domain/src/main/kotlin/com/going/domain/entity/response/SignOutModel.kt create mode 100644 domain/src/main/kotlin/com/going/domain/repository/SettingRepository.kt diff --git a/app/src/main/java/com/going/going/di/DataSourceModule.kt b/app/src/main/java/com/going/going/di/DataSourceModule.kt index 66020dce..08911089 100644 --- a/app/src/main/java/com/going/going/di/DataSourceModule.kt +++ b/app/src/main/java/com/going/going/di/DataSourceModule.kt @@ -2,8 +2,10 @@ package com.going.going.di import com.going.data.datasource.AuthDataSource import com.going.data.datasource.MockDataSource +import com.going.data.datasource.SettingDataSource import com.going.data.datasourceImpl.AuthDataSourceImpl import com.going.data.datasourceImpl.MockDataSourceImpl +import com.going.data.datasourceImpl.SettingDataSourceImpl import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -23,4 +25,9 @@ object DataSourceModule { @Singleton fun provideAuthDataSource(authDataSourceImpl: AuthDataSourceImpl): AuthDataSource = authDataSourceImpl + + @Provides + @Singleton + fun provideSettingDataSource(settingDataSourceImpl: SettingDataSourceImpl): SettingDataSource = + settingDataSourceImpl } diff --git a/app/src/main/java/com/going/going/di/RepositoryModule.kt b/app/src/main/java/com/going/going/di/RepositoryModule.kt index d8fcf24a..474639ab 100644 --- a/app/src/main/java/com/going/going/di/RepositoryModule.kt +++ b/app/src/main/java/com/going/going/di/RepositoryModule.kt @@ -2,9 +2,11 @@ package com.going.going.di import com.going.data.repositoryImpl.AuthRepositoryImpl import com.going.data.repositoryImpl.MockRepositoryImpl +import com.going.data.repositoryImpl.SettingRepositoryImpl import com.going.data.repositoryImpl.TokenRepositoryImpl import com.going.domain.repository.AuthRepository import com.going.domain.repository.MockRepository +import com.going.domain.repository.SettingRepository import com.going.domain.repository.TokenRepository import dagger.Module import dagger.Provides @@ -30,4 +32,9 @@ object RepositoryModule { @Singleton fun provideTokenRepository(tokenRepositoryImpl: TokenRepositoryImpl): TokenRepository = tokenRepositoryImpl + + @Provides + @Singleton + fun provideSettingRepository(settingRepositoryImpl: SettingRepositoryImpl): SettingRepository = + settingRepositoryImpl } diff --git a/app/src/main/java/com/going/going/di/ServiceModule.kt b/app/src/main/java/com/going/going/di/ServiceModule.kt index 807674da..cd422b06 100644 --- a/app/src/main/java/com/going/going/di/ServiceModule.kt +++ b/app/src/main/java/com/going/going/di/ServiceModule.kt @@ -2,6 +2,8 @@ package com.going.going.di import com.going.data.service.AuthService import com.going.data.service.MockService +import com.going.data.service.SettingService +import com.going.going.di.qualifier.JWT import com.going.going.di.qualifier.KAKAO import dagger.Module import dagger.Provides @@ -23,4 +25,9 @@ object ServiceModule { @Singleton fun provideAuthService(@KAKAO retrofit: Retrofit): AuthService = retrofit.create(AuthService::class.java) + + @Provides + @Singleton + fun provideSettingService(@JWT retrofit: Retrofit): SettingService = + retrofit.create(SettingService::class.java) } diff --git a/data/src/main/java/com/going/data/datasource/SettingDataSource.kt b/data/src/main/java/com/going/data/datasource/SettingDataSource.kt new file mode 100644 index 00000000..0b7cab84 --- /dev/null +++ b/data/src/main/java/com/going/data/datasource/SettingDataSource.kt @@ -0,0 +1,7 @@ +package com.going.data.datasource + +import com.going.data.dto.response.SignOutResponseDto + +interface SettingDataSource { + suspend fun patchSignOut(): SignOutResponseDto +} diff --git a/data/src/main/java/com/going/data/datasourceImpl/SettingDataSourceImpl.kt b/data/src/main/java/com/going/data/datasourceImpl/SettingDataSourceImpl.kt new file mode 100644 index 00000000..7e3444ca --- /dev/null +++ b/data/src/main/java/com/going/data/datasourceImpl/SettingDataSourceImpl.kt @@ -0,0 +1,12 @@ +package com.going.data.datasourceImpl + +import com.going.data.datasource.SettingDataSource +import com.going.data.dto.response.SignOutResponseDto +import com.going.data.service.SettingService +import javax.inject.Inject + +class SettingDataSourceImpl @Inject constructor( + private val settingService: SettingService, +) : SettingDataSource { + override suspend fun patchSignOut(): SignOutResponseDto = settingService.patchSignOut() +} diff --git a/data/src/main/java/com/going/data/dto/response/SignOutResponseDto.kt b/data/src/main/java/com/going/data/dto/response/SignOutResponseDto.kt new file mode 100644 index 00000000..6a03f5e2 --- /dev/null +++ b/data/src/main/java/com/going/data/dto/response/SignOutResponseDto.kt @@ -0,0 +1,16 @@ +package com.going.data.dto.response + +import com.going.domain.entity.response.SignOutModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class SignOutResponseDto( + @SerialName("status") + val status: Int, + @SerialName("message") + val message: String, +) { + fun toSignOutModel() = + SignOutModel(status, message) +} diff --git a/data/src/main/java/com/going/data/repositoryImpl/SettingRepositoryImpl.kt b/data/src/main/java/com/going/data/repositoryImpl/SettingRepositoryImpl.kt new file mode 100644 index 00000000..e1045509 --- /dev/null +++ b/data/src/main/java/com/going/data/repositoryImpl/SettingRepositoryImpl.kt @@ -0,0 +1,14 @@ +package com.going.data.repositoryImpl + +import com.going.data.datasource.SettingDataSource +import com.going.domain.entity.response.SignOutModel +import com.going.domain.repository.SettingRepository +import javax.inject.Inject + +class SettingRepositoryImpl @Inject constructor( + private val settingDataSource: SettingDataSource, +) : SettingRepository { + override suspend fun patchSignOut(): Result = runCatching { + settingDataSource.patchSignOut().toSignOutModel() + } +} diff --git a/data/src/main/java/com/going/data/service/SettingService.kt b/data/src/main/java/com/going/data/service/SettingService.kt new file mode 100644 index 00000000..6473cacd --- /dev/null +++ b/data/src/main/java/com/going/data/service/SettingService.kt @@ -0,0 +1,9 @@ +package com.going.data.service + +import com.going.data.dto.response.SignOutResponseDto +import retrofit2.http.PATCH + +interface SettingService { + @PATCH("api/users/signout") + suspend fun patchSignOut(): SignOutResponseDto +} diff --git a/domain/src/main/kotlin/com/going/domain/entity/response/SignOutModel.kt b/domain/src/main/kotlin/com/going/domain/entity/response/SignOutModel.kt new file mode 100644 index 00000000..991849e2 --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/entity/response/SignOutModel.kt @@ -0,0 +1,6 @@ +package com.going.domain.entity.response + +data class SignOutModel( + val status: Int, + val message: String, +) diff --git a/domain/src/main/kotlin/com/going/domain/repository/SettingRepository.kt b/domain/src/main/kotlin/com/going/domain/repository/SettingRepository.kt new file mode 100644 index 00000000..456a23d0 --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/repository/SettingRepository.kt @@ -0,0 +1,7 @@ +package com.going.domain.repository + +import com.going.domain.entity.response.SignOutModel + +interface SettingRepository { + suspend fun patchSignOut(): Result +} From 7ac8381b08f1d4af4ceb88a9b372d87635be26f9 Mon Sep 17 00:00:00 2001 From: Dongmin Date: Wed, 10 Jan 2024 15:24:25 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[FEAT/#55]=20conflict=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/going/doorip/di/AuthInterceptor.kt | 4 ++-- app/src/main/java/com/going/doorip/di/RetrofitModule.kt | 8 +++----- .../tendencytest/result/TendencyTestResultActivity.kt | 5 +++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt b/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt index fa46823d..93af2c12 100644 --- a/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt +++ b/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt @@ -4,7 +4,7 @@ import android.content.Context import com.going.data.dto.BaseResponse import com.going.data.local.GoingDataStore import com.going.domain.entity.response.AuthTokenModel -import com.going.going.BuildConfig.BASE_URL +import com.going.doorip.BuildConfig.BASE_URL import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.serialization.json.Json import okhttp3.Interceptor @@ -32,7 +32,7 @@ class AuthInterceptor @Inject constructor( CODE_TOKEN_EXPIRED -> { try { val refreshTokenRequest = originalRequest.newBuilder().post("".toRequestBody()) - .url("$BASE_URL/api/v1/auth/token/issue") + .url("$BASE_URL/api/users/reissue") .addHeader(AUTHORIZATION, dataStore.refreshToken) .build() val refreshTokenResponse = chain.proceed(refreshTokenRequest) diff --git a/app/src/main/java/com/going/doorip/di/RetrofitModule.kt b/app/src/main/java/com/going/doorip/di/RetrofitModule.kt index 860e1e2d..8de00dab 100644 --- a/app/src/main/java/com/going/doorip/di/RetrofitModule.kt +++ b/app/src/main/java/com/going/doorip/di/RetrofitModule.kt @@ -1,11 +1,9 @@ package com.going.doorip.di - - -import com.going.doorip.BuildConfig.BASE_URL import com.going.doorip.BuildConfig.BASE_URL -import com.going.doorip.di.qualifier.JWT -import com.going.doorip.di.qualifier.KAKAO +import com.going.going.di.AuthInterceptor +import com.going.going.di.qualifier.JWT +import com.going.going.di.qualifier.KAKAO import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import dagger.Module import dagger.Provides diff --git a/presentation/src/main/java/com/going/presentation/tendencytest/result/TendencyTestResultActivity.kt b/presentation/src/main/java/com/going/presentation/tendencytest/result/TendencyTestResultActivity.kt index 83daa218..0ba5cb11 100644 --- a/presentation/src/main/java/com/going/presentation/tendencytest/result/TendencyTestResultActivity.kt +++ b/presentation/src/main/java/com/going/presentation/tendencytest/result/TendencyTestResultActivity.kt @@ -1,5 +1,6 @@ package com.going.presentation.tendencytest.result +import android.media.SubtitleData import android.os.Bundle import android.text.SpannableString import android.text.Spanned @@ -27,8 +28,8 @@ class TendencyTestResultActivity : tvTendencyTestResultTitle.text = getString(R.string.tendency_test_result_title, "찐두릅") viewModel.mockTendencyResult.apply { - tvTendencyTestResultType.text = tendencyTitle - tvTendencyTestResultSubType.text = tendencySubTitle + tvTendencyTestResultType.text = profileTitle + tvTendencyTestResultSubType.text = profileSubTitle tvTendencyTestResultTag1.text = tags[0] tvTendencyTestResultTag2.text = tags[1] From 7b4b0fbfdbcdf44190fe893fc16b8d8388c20991 Mon Sep 17 00:00:00 2001 From: Dongmin Date: Wed, 10 Jan 2024 17:08:22 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[FEAT/#55]=20token=20interceptor=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=9E=90=EB=8F=99=20=EB=B3=80?= =?UTF-8?q?=ED=99=98=EA=B8=B0=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/going/doorip/di/AuthInterceptor.kt | 16 ++++------ .../com/going/doorip/di/RetrofitModule.kt | 30 ++----------------- .../java/com/going/doorip/di/ServiceModule.kt | 8 ++--- .../doorip/di/qualifier/RetrofitQualifier.kt | 4 --- .../repositoryImpl/TokenRepositoryImpl.kt | 6 +++- .../domain/repository/TokenRepository.kt | 1 + .../onboarding/splash/SplashViewModel.kt | 4 ++- .../com/going/presentation/util/JsonExt.kt | 5 +++- 8 files changed, 24 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt b/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt index 93af2c12..53490a5b 100644 --- a/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt +++ b/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt @@ -21,7 +21,10 @@ class AuthInterceptor @Inject constructor( ) : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val originalRequest = chain.request() - val authRequest = if (dataStore.accessToken != "") { + + Timber.d("GET ACCESS TOKEN : ${dataStore.accessToken}") + + val authRequest = if (dataStore.accessToken.isNotBlank()) { originalRequest.newAuthBuilder().build() } else { originalRequest @@ -51,17 +54,8 @@ class AuthInterceptor @Inject constructor( val newRequest = originalRequest.newAuthBuilder().build() return chain.proceed(newRequest) } - - with(dataStore) { - accessToken = "" - refreshToken = "" - } } catch (t: Throwable) { Timber.e(t) - with(dataStore) { - accessToken = "" - refreshToken = "" - } } } } @@ -69,7 +63,7 @@ class AuthInterceptor @Inject constructor( } private fun Request.newAuthBuilder() = - this.newBuilder().addHeader(AUTHORIZATION, "${dataStore.accessToken}") + this.newBuilder().addHeader(AUTHORIZATION, "Bearer ${dataStore.accessToken}") companion object { private const val CODE_TOKEN_EXPIRED = 401 diff --git a/app/src/main/java/com/going/doorip/di/RetrofitModule.kt b/app/src/main/java/com/going/doorip/di/RetrofitModule.kt index 8de00dab..435739aa 100644 --- a/app/src/main/java/com/going/doorip/di/RetrofitModule.kt +++ b/app/src/main/java/com/going/doorip/di/RetrofitModule.kt @@ -3,7 +3,6 @@ package com.going.doorip.di import com.going.doorip.BuildConfig.BASE_URL import com.going.going.di.AuthInterceptor import com.going.going.di.qualifier.JWT -import com.going.going.di.qualifier.KAKAO import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import dagger.Module import dagger.Provides @@ -57,16 +56,11 @@ object RetrofitModule { @Provides @Singleton - @KAKAO - fun provideKAKAOOkHttpClient( - loggingInterceptor: Interceptor, - ): OkHttpClient = OkHttpClient.Builder() - .addInterceptor(loggingInterceptor) - .build() + @JWT + fun provideAuthInterceptor(authInterceptor: AuthInterceptor): Interceptor = authInterceptor @Provides @Singleton - @JWT fun provideJWTOkHttpClient( loggingInterceptor: Interceptor, @JWT authInterceptor: Interceptor, @@ -77,26 +71,8 @@ object RetrofitModule { @Provides @Singleton - @JWT - fun provideAuthInterceptor(interceptor: AuthInterceptor): Interceptor = interceptor - - @Provides - @Singleton - @KAKAO - fun provideKAKAORetrofit( - @KAKAO client: OkHttpClient, - factory: Converter.Factory, - ): Retrofit = Retrofit.Builder() - .baseUrl(BASE_URL) - .client(client) - .addConverterFactory(factory) - .build() - - @Provides - @Singleton - @JWT fun provideJWTRetrofit( - @JWT client: OkHttpClient, + client: OkHttpClient, factory: Converter.Factory, ): Retrofit = Retrofit.Builder() .baseUrl(BASE_URL) diff --git a/app/src/main/java/com/going/doorip/di/ServiceModule.kt b/app/src/main/java/com/going/doorip/di/ServiceModule.kt index b6f06a3d..bd88da51 100644 --- a/app/src/main/java/com/going/doorip/di/ServiceModule.kt +++ b/app/src/main/java/com/going/doorip/di/ServiceModule.kt @@ -3,8 +3,6 @@ package com.going.doorip.di import com.going.data.service.AuthService import com.going.data.service.MockService import com.going.data.service.SettingService -import com.going.going.di.qualifier.JWT -import com.going.going.di.qualifier.KAKAO import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -18,16 +16,16 @@ object ServiceModule { @Provides @Singleton - fun provideMockService(@KAKAO retrofit: Retrofit): MockService = + fun provideMockService(retrofit: Retrofit): MockService = retrofit.create(MockService::class.java) @Provides @Singleton - fun provideAuthService(@KAKAO retrofit: Retrofit): AuthService = + fun provideAuthService(retrofit: Retrofit): AuthService = retrofit.create(AuthService::class.java) @Provides @Singleton - fun provideSettingService(@JWT retrofit: Retrofit): SettingService = + fun provideSettingService(retrofit: Retrofit): SettingService = retrofit.create(SettingService::class.java) } diff --git a/app/src/main/java/com/going/doorip/di/qualifier/RetrofitQualifier.kt b/app/src/main/java/com/going/doorip/di/qualifier/RetrofitQualifier.kt index 5fc7194f..ea348550 100644 --- a/app/src/main/java/com/going/doorip/di/qualifier/RetrofitQualifier.kt +++ b/app/src/main/java/com/going/doorip/di/qualifier/RetrofitQualifier.kt @@ -5,7 +5,3 @@ import javax.inject.Qualifier @Qualifier @Retention(AnnotationRetention.BINARY) annotation class JWT - -@Qualifier -@Retention(AnnotationRetention.BINARY) -annotation class KAKAO diff --git a/data/src/main/java/com/going/data/repositoryImpl/TokenRepositoryImpl.kt b/data/src/main/java/com/going/data/repositoryImpl/TokenRepositoryImpl.kt index ba4b219d..ab3efccb 100644 --- a/data/src/main/java/com/going/data/repositoryImpl/TokenRepositoryImpl.kt +++ b/data/src/main/java/com/going/data/repositoryImpl/TokenRepositoryImpl.kt @@ -8,11 +8,15 @@ class TokenRepositoryImpl @Inject constructor( private val goingDataStore: GoingDataStore, ) : TokenRepository { override fun getAccessToken(): String = goingDataStore.accessToken + override fun getRefreshToken(): String = goingDataStore.refreshToken override fun setTokens(accessToken: String, refreshToken: String) { goingDataStore.accessToken = accessToken goingDataStore.refreshToken = refreshToken } - override fun getRefreshToken(): String = goingDataStore.refreshToken + override fun clearTokens() { + goingDataStore.accessToken = "" + goingDataStore.refreshToken = "" + } } diff --git a/domain/src/main/kotlin/com/going/domain/repository/TokenRepository.kt b/domain/src/main/kotlin/com/going/domain/repository/TokenRepository.kt index dbcbbff1..45d8a7be 100644 --- a/domain/src/main/kotlin/com/going/domain/repository/TokenRepository.kt +++ b/domain/src/main/kotlin/com/going/domain/repository/TokenRepository.kt @@ -6,4 +6,5 @@ interface TokenRepository { fun getRefreshToken(): String fun setTokens(accessToken: String, refreshToken: String) + fun clearTokens() } diff --git a/presentation/src/main/java/com/going/presentation/onboarding/splash/SplashViewModel.kt b/presentation/src/main/java/com/going/presentation/onboarding/splash/SplashViewModel.kt index 5ea3c164..fae8ed79 100644 --- a/presentation/src/main/java/com/going/presentation/onboarding/splash/SplashViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/onboarding/splash/SplashViewModel.kt @@ -9,5 +9,7 @@ import javax.inject.Inject class SplashViewModel @Inject constructor( private val tokenRepository: TokenRepository, ) : ViewModel() { - fun getHasAccessToken(): Boolean = tokenRepository.getAccessToken() != "" + fun getHasAccessToken(): Boolean = tokenRepository.getAccessToken().isNotBlank() + + fun clearTokens() = tokenRepository.clearTokens() } diff --git a/presentation/src/main/java/com/going/presentation/util/JsonExt.kt b/presentation/src/main/java/com/going/presentation/util/JsonExt.kt index 9aea58f3..a6aa437d 100644 --- a/presentation/src/main/java/com/going/presentation/util/JsonExt.kt +++ b/presentation/src/main/java/com/going/presentation/util/JsonExt.kt @@ -1,11 +1,14 @@ package com.going.presentation.util +import android.util.Log import org.json.JSONObject import retrofit2.HttpException fun toErrorCode(throwable: Throwable): String = if (throwable is HttpException) { val jsonTemp = throwable.response()?.errorBody()?.byteString().toString() - val json = jsonTemp.slice(6 until jsonTemp.length) + Log.e("TAG", "toErrorCode: $jsonTemp", ) + val json = jsonTemp.slice(6 until jsonTemp.length - 2) + "}" + Log.e("TAG", "toErrorCode: $json", ) JSONObject(json).getString("code") } else { "NOT_HTTP" From 7604813e1ca95fca326672099227e1fcf8d425b8 Mon Sep 17 00:00:00 2001 From: Dongmin Date: Wed, 10 Jan 2024 17:11:34 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[CHORE/#55]=20error=20=EB=B0=9C=EA=B2=AC?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/going/presentation/util/JsonExt.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/presentation/src/main/java/com/going/presentation/util/JsonExt.kt b/presentation/src/main/java/com/going/presentation/util/JsonExt.kt index a6aa437d..65e7d6b6 100644 --- a/presentation/src/main/java/com/going/presentation/util/JsonExt.kt +++ b/presentation/src/main/java/com/going/presentation/util/JsonExt.kt @@ -13,3 +13,5 @@ fun toErrorCode(throwable: Throwable): String = if (throwable is HttpException) } else { "NOT_HTTP" } + +// 기능 오류 발견!!!! 반드시 수정 필요!!!!!! From fd9a76cf18e3044b05d367e77524be2f59c009ba Mon Sep 17 00:00:00 2001 From: Dongmin Date: Wed, 10 Jan 2024 17:12:51 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[CHORE/#55]=20=ED=8C=A8=ED=82=A4=EA=B8=B0?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/going/doorip/di/AuthInterceptor.kt | 2 +- .../java/com/going/doorip/di/qualifier/RetrofitQualifier.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt b/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt index 53490a5b..fe73f8b8 100644 --- a/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt +++ b/app/src/main/java/com/going/doorip/di/AuthInterceptor.kt @@ -1,4 +1,4 @@ -package com.going.going.di +package com.going.doorip.di import android.content.Context import com.going.data.dto.BaseResponse diff --git a/app/src/main/java/com/going/doorip/di/qualifier/RetrofitQualifier.kt b/app/src/main/java/com/going/doorip/di/qualifier/RetrofitQualifier.kt index ea348550..c4935bf2 100644 --- a/app/src/main/java/com/going/doorip/di/qualifier/RetrofitQualifier.kt +++ b/app/src/main/java/com/going/doorip/di/qualifier/RetrofitQualifier.kt @@ -1,4 +1,4 @@ -package com.going.going.di.qualifier +package com.going.doorip.di.qualifier import javax.inject.Qualifier