Skip to content

Commit

Permalink
[chore] 리뷰 반영
Browse files Browse the repository at this point in the history
- null 값인 경우 "" 반환 대신 orEmpty 적용
- ServiceModule 내부 레트로핏 생성 코드 수정
- UserTokenResponseModel 기본값 생성
- Mapper as -> to 변경
  • Loading branch information
fbghgus123 committed Jul 6, 2024
1 parent f99abfd commit 11e112c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ interface UserLocalDataSource {
fun getUserAccessToken(): Flow<String>

fun getIsFirstEntry(): Flow<Boolean>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import com.mashup.dorabangs.data.model.DeviceTokenDataModel
interface UserRemoteDataSource {

suspend fun registerUser(deviceToken: DeviceTokenDataModel): String
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?: ""
}
?.accessToken.orEmpty()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -26,4 +25,4 @@ abstract class DataSourceModule {
abstract fun bindUserRemoteDataSource(
dataSource: UserRemoteDataSourceImpl,
): UserRemoteDataSource
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -16,6 +17,5 @@ object ServiceModule {
@Reusable
fun providesUserService(
retrofit: Retrofit,
): UserService =
retrofit.create(UserService::class.java)
): UserService = retrofit.create()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
}
}

0 comments on commit 11e112c

Please sign in to comment.