From 11e112c705a6810c267b01c7299cd736f341334b Mon Sep 17 00:00:00 2001 From: fbghgus123 Date: Sat, 6 Jul 2024 18:32:56 +0900 Subject: [PATCH] =?UTF-8?q?[chore]=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - null 값인 경우 "" 반환 대신 orEmpty 적용 - ServiceModule 내부 레트로핏 생성 코드 수정 - UserTokenResponseModel 기본값 생성 - Mapper as -> to 변경 --- .../java/com/mashup/dorabangs/splash/SplashViewModel.kt | 8 ++++---- .../data/datasource/local/api/UserLocalDataSource.kt | 2 +- .../data/datasource/remote/api/UserRemoteDataSource.kt | 2 +- .../datasource/remote/impl/UserRemoteDataSourceImpl.kt | 6 +++--- .../com/mashup/dorabangs/data/di/DataSourceModule.kt | 3 +-- .../kotlin/com/mashup/dorabangs/data/di/ServiceModule.kt | 4 ++-- .../mashup/dorabangs/data/model/DeviceTokenDataModel.kt | 4 ++-- .../mashup/dorabangs/data/model/UserTokenResponseModel.kt | 6 +++--- .../dorabangs/data/repository/UserRepositoryImpl.kt | 4 ++-- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/mashup/dorabangs/splash/SplashViewModel.kt b/app/src/main/java/com/mashup/dorabangs/splash/SplashViewModel.kt index 9a066996..c7599cbe 100644 --- a/app/src/main/java/com/mashup/dorabangs/splash/SplashViewModel.kt +++ b/app/src/main/java/com/mashup/dorabangs/splash/SplashViewModel.kt @@ -11,7 +11,7 @@ import com.mashup.dorabangs.domain.usecase.user.SetUserAccessTokenUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.withTimeout import javax.inject.Inject @@ -27,12 +27,12 @@ class SplashViewModel @Inject constructor( fun checkUserToken(userId: String) { viewModelScope.doraLaunch { - val userAccessToken = getUserAccessTokenUseCase().first() - .ifEmpty { + val userAccessToken = getUserAccessTokenUseCase().firstOrNull() + ?.ifEmpty { val token = registerUserUseCase(DeviceToken(userId)) setUserAccessTokenUseCase(token) token - } + }.orEmpty() withTimeout(SPLASH_SCREEN_TIME) { if (userAccessToken.isNotEmpty()) { diff --git a/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/local/api/UserLocalDataSource.kt b/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/local/api/UserLocalDataSource.kt index 9dada452..0ebffea6 100644 --- a/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/local/api/UserLocalDataSource.kt +++ b/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/local/api/UserLocalDataSource.kt @@ -11,4 +11,4 @@ interface UserLocalDataSource { fun getUserAccessToken(): Flow fun getIsFirstEntry(): Flow -} \ No newline at end of file +} diff --git a/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/remote/api/UserRemoteDataSource.kt b/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/remote/api/UserRemoteDataSource.kt index d61d56f8..47186996 100644 --- a/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/remote/api/UserRemoteDataSource.kt +++ b/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/remote/api/UserRemoteDataSource.kt @@ -5,4 +5,4 @@ import com.mashup.dorabangs.data.model.DeviceTokenDataModel interface UserRemoteDataSource { suspend fun registerUser(deviceToken: DeviceTokenDataModel): String -} \ No newline at end of file +} diff --git a/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/remote/impl/UserRemoteDataSourceImpl.kt b/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/remote/impl/UserRemoteDataSourceImpl.kt index d75f09fb..ca4520bd 100644 --- a/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/remote/impl/UserRemoteDataSourceImpl.kt +++ b/data/src/main/kotlin/com/mashup/dorabangs/data/datasource/remote/impl/UserRemoteDataSourceImpl.kt @@ -6,11 +6,11 @@ import com.mashup.dorabangs.data.network.service.UserService import javax.inject.Inject class UserRemoteDataSourceImpl @Inject constructor( - private val userService: UserService + private val userService: UserService, ) : UserRemoteDataSource { override suspend fun registerUser(deviceToken: DeviceTokenDataModel): String = userService.registerUser(deviceToken) ?.data - ?.accessToken ?: "" -} \ No newline at end of file + ?.accessToken.orEmpty() +} diff --git a/data/src/main/kotlin/com/mashup/dorabangs/data/di/DataSourceModule.kt b/data/src/main/kotlin/com/mashup/dorabangs/data/di/DataSourceModule.kt index 145a7555..a173f709 100644 --- a/data/src/main/kotlin/com/mashup/dorabangs/data/di/DataSourceModule.kt +++ b/data/src/main/kotlin/com/mashup/dorabangs/data/di/DataSourceModule.kt @@ -9,7 +9,6 @@ import dagger.Module import dagger.Reusable import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) @@ -26,4 +25,4 @@ abstract class DataSourceModule { abstract fun bindUserRemoteDataSource( dataSource: UserRemoteDataSourceImpl, ): UserRemoteDataSource -} \ No newline at end of file +} diff --git a/data/src/main/kotlin/com/mashup/dorabangs/data/di/ServiceModule.kt b/data/src/main/kotlin/com/mashup/dorabangs/data/di/ServiceModule.kt index 541e620b..47037408 100644 --- a/data/src/main/kotlin/com/mashup/dorabangs/data/di/ServiceModule.kt +++ b/data/src/main/kotlin/com/mashup/dorabangs/data/di/ServiceModule.kt @@ -7,6 +7,7 @@ import dagger.Reusable import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import retrofit2.Retrofit +import retrofit2.create @Module @InstallIn(SingletonComponent::class) @@ -16,6 +17,5 @@ object ServiceModule { @Reusable fun providesUserService( retrofit: Retrofit, - ): UserService = - retrofit.create(UserService::class.java) + ): UserService = retrofit.create() } diff --git a/data/src/main/kotlin/com/mashup/dorabangs/data/model/DeviceTokenDataModel.kt b/data/src/main/kotlin/com/mashup/dorabangs/data/model/DeviceTokenDataModel.kt index 6dbea921..6816e337 100644 --- a/data/src/main/kotlin/com/mashup/dorabangs/data/model/DeviceTokenDataModel.kt +++ b/data/src/main/kotlin/com/mashup/dorabangs/data/model/DeviceTokenDataModel.kt @@ -8,10 +8,10 @@ data class DeviceTokenDataModel( val deviceToken: String, ) -fun DeviceTokenDataModel.asDomain() = DeviceToken( +fun DeviceTokenDataModel.toDomain() = DeviceToken( deviceToken = this.deviceToken, ) -fun DeviceToken.asData() = DeviceTokenDataModel( +fun DeviceToken.toData() = DeviceTokenDataModel( deviceToken = this.deviceToken, ) diff --git a/data/src/main/kotlin/com/mashup/dorabangs/data/model/UserTokenResponseModel.kt b/data/src/main/kotlin/com/mashup/dorabangs/data/model/UserTokenResponseModel.kt index 6cd5969b..fe17d923 100644 --- a/data/src/main/kotlin/com/mashup/dorabangs/data/model/UserTokenResponseModel.kt +++ b/data/src/main/kotlin/com/mashup/dorabangs/data/model/UserTokenResponseModel.kt @@ -4,11 +4,11 @@ import kotlinx.serialization.Serializable @Serializable data class UserAccessTokenResponseModel( - val data: AccessTokenDataModel, - val success: Boolean, + val data: AccessTokenDataModel = AccessTokenDataModel(), + val success: Boolean = false, ) @Serializable data class AccessTokenDataModel( - val accessToken: String, + val accessToken: String = "", ) diff --git a/data/src/main/kotlin/com/mashup/dorabangs/data/repository/UserRepositoryImpl.kt b/data/src/main/kotlin/com/mashup/dorabangs/data/repository/UserRepositoryImpl.kt index e57f1d53..df752aa8 100644 --- a/data/src/main/kotlin/com/mashup/dorabangs/data/repository/UserRepositoryImpl.kt +++ b/data/src/main/kotlin/com/mashup/dorabangs/data/repository/UserRepositoryImpl.kt @@ -2,7 +2,7 @@ package com.mashup.dorabangs.data.repository import com.mashup.dorabangs.data.datasource.local.api.UserLocalDataSource import com.mashup.dorabangs.data.datasource.remote.api.UserRemoteDataSource -import com.mashup.dorabangs.data.model.asData +import com.mashup.dorabangs.data.model.toData import com.mashup.dorabangs.domain.model.DeviceToken import com.mashup.dorabangs.domain.repository.UserRepository import kotlinx.coroutines.flow.Flow @@ -29,6 +29,6 @@ class UserRepositoryImpl @Inject constructor( } override suspend fun registerDeviceToken(deviceToken: DeviceToken): String { - return userRemoteDataSource.registerUser(deviceToken.asData()) + return userRemoteDataSource.registerUser(deviceToken.toData()) } }