Skip to content

Commit

Permalink
refactor : orEmpty 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
nohjunh committed May 11, 2024
1 parent ab31136 commit bfe2b30
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class ResultRepositoryImpl @Inject constructor(
}

override suspend fun getSingleResults(): Result<SingleResult> {
val singleId = singlePreferencesDataSource.getSingleId().first() ?: ""
val singleId = singlePreferencesDataSource
.getSingleId().first().orEmpty()
return resultDataSource
.getSingleResults(singleId)
.toResultModel { it.toDomainModel() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun NavGraphBuilder.partyRoute(
val partyCode = backStackEntry.arguments?.getString("code")
val hasManagerPrivileges = backStackEntry.arguments?.getBoolean("hasManagerPrivileges")
PartyRoomScreen(
partyCode = partyCode ?: "",
partyCode = partyCode.orEmpty(),
hasManagerPrivileges = hasManagerPrivileges ?: false,
navigateToParty = navigateToParty,
navigateToBattleRunningWithDistance = navigateToBattleRunningWithDistance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import javax.inject.Singleton
class AuthAuthenticator @Inject constructor(
private val tokenDataSource: TokenDataSource,
private val context: Context,
private val tokenExpirationNotifier: TokenExpirationNotifier
private val tokenExpirationNotifier: TokenExpirationNotifier,
) : Authenticator {

private val googleAuthUiClient by lazy {
Expand All @@ -51,13 +51,13 @@ class AuthAuthenticator @Inject constructor(
// Token 만료 알림 -> 이벤트 브로드캐스팅
tokenExpirationNotifier.notifyRefreshTokenExpired()
return@runBlocking null
}else {
} else {
/* 정상적으로 새로운 Token Set을 받아온 경우 */
newAccessToken.body()?.let {
tokenDataSource.saveAccessToken(it.accessToken ?: "")
tokenDataSource.saveRefreshToken(it.refreshToken ?: "")
tokenDataSource.saveAccessToken(it.accessToken.orEmpty())
tokenDataSource.saveRefreshToken(it.refreshToken.orEmpty())
response.request.newBuilder()
.header("Authorization", it.accessToken ?: "")
.header("Authorization", it.accessToken.orEmpty())
.build()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ fun BattleEventResponse.toDomainModel(): BattleEvent {
)
is BattleEventResponse.BattleBaseRunningResponse -> BattleEvent.BattleRunning(
isFinished = this.data?.isFinished ?: false,
runnerId = this.data?.runnerId ?: "",
runnerId = this.data?.runnerId.orEmpty(),
distance = this.data?.distance ?: 0.0
)
is BattleEventResponse.BattleBaseFinishedResponse -> BattleEvent.BattleFinished(
runnerId = this.data?.runnerId ?: ""
runnerId = this.data?.runnerId.orEmpty()
)
is BattleEventResponse.BattleDefaultResponse -> BattleEvent.BattleDefault(message = this.message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class BattleResultResponse(
@SerializedName("startTime")
val startTime: String?,
@SerializedName("targetDistance")
val targetDistance: Int?
val targetDistance: Int?,
)

fun BattleResultResponse.toDomainModel(): BattleResult {
Expand All @@ -26,11 +26,24 @@ fun BattleResultResponse.toDomainModel(): BattleResult {
val parsedStartTime = this.startTime?.let { LocalDateTime.parse(it, localDateTimeFormatter) }

return BattleResult(
battleRunnerStatus = this.battleRunnerStatus?.map { it.toDomainModel(parsedStartTime) } ?: emptyList(),
startTime = parsedStartTime?.let { formatTime(it) } ?: "", // "xx:xx" 형식화
battleRunnerStatus = this.battleRunnerStatus?.map { it.toDomainModel(parsedStartTime) }
?: emptyList(),
startTime = parsedStartTime?.let {
formatTime(it)
}
.orEmpty(), // "xx:xx" 형식화
targetDistance = this.targetDistance ?: 0,
targetDistanceFormatted = this.targetDistance?.let { formatDistanceWithComma(it) } ?: "", // 쉼표로 형식화
targetDistanceInKm = this.targetDistance?.let { formatDistanceInKm(it) } ?: "", // km 단위로 형식화
battleDate = parsedStartTime?.let { formatDate(it) } ?: "" // "x월 x일" 형식화
targetDistanceFormatted = this.targetDistance?.let {
formatDistanceWithComma(it)
}
.orEmpty(), // 쉼표로 형식화
targetDistanceInKm = this.targetDistance?.let {
formatDistanceInKm(it)
}
.orEmpty(), // km 단위로 형식화
battleDate = parsedStartTime?.let {
formatDate(it)
}
.orEmpty() // "x월 x일" 형식화
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data class CancelMatchResponse(
)

fun CancelMatchResponse.toDomainModel() = CancelMatch(
message = this.message ?: ""
message = this.message.orEmpty()
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data class DeleteAccountResponse(
)

fun DeleteAccountResponse.toDomainModel() = DeleteAccount(
message = this.message ?: ""
message = this.message.orEmpty()
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data class MatchStatusResponse(
)

fun MatchStatusResponse.toDomainModel() = MatchStatus(
message = this.message ?: ""
message = this.message.orEmpty()
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data class PartyCodeResponse(
)

fun PartyCodeResponse.toDomainModel() = PartyCode(
code = this.code ?: ""
code = this.code.orEmpty()
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ fun RunningHistoryDetailResponse.getParsedDate(): LocalDateTime? {
}

fun RunningHistoryDetailResponse.getFormattedDate(): String {
return getParsedDate()?.let { formatDate(it) } ?: ""
return getParsedDate()?.let { formatDate(it) }.orEmpty()
}

fun RunningHistoryDetailResponse.toDomainModel(): RunningHistoryDetail {
return RunningHistoryDetail(
id = this.id ?: "",
id = this.id.orEmpty(),
date = getFormattedDate(),
runningTime = getFormattedRunningTime(),
distanceFormatted = formatDistanceWithComma(this.distance?.toInt() ?: 0)
Expand All @@ -50,7 +50,7 @@ fun RunningHistoryDetailResponse.toDomainModel(): RunningHistoryDetail {

fun RunningHistoryDetailResponse.toSingleRunningHistoryEntity(): SingleRunningHistoryEntity {
return SingleRunningHistoryEntity(
id = this.id ?: "",
id = this.id.orEmpty(),
date = getFormattedDate(),
runningTime = getFormattedRunningTime(),
distanceFormatted = formatDistanceWithComma(this.distance?.toInt() ?: 0)
Expand All @@ -59,7 +59,7 @@ fun RunningHistoryDetailResponse.toSingleRunningHistoryEntity(): SingleRunningHi

fun RunningHistoryDetailResponse.toBattleRunningHistoryEntity(): BattleRunningHistoryEntity {
return BattleRunningHistoryEntity(
id = this.id ?: "",
id = this.id.orEmpty(),
date = getFormattedDate(),
runningTime = getFormattedRunningTime(),
distanceFormatted = formatDistanceWithComma(this.distance?.toInt() ?: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class SingleResultResponse(
@SerializedName("runningTime")
val runningTime: RunningTimeResponse,
@SerializedName("records")
val records: List<SingleRunnerRecordResponse>
val records: List<SingleRunnerRecordResponse>,
)

fun SingleResultResponse.toDomainModel(): SingleResult {
Expand All @@ -34,6 +34,8 @@ fun SingleResultResponse.toDomainModel(): SingleResult {
targetDistance = targetDistance,
targetDistanceFormatted = formatDistanceWithComma(targetDistance),
targetDistanceInKm = formatDistanceInKm(targetDistance),
singleDate = parsedStartTime?.let { formatDate(it) } ?: "" // "x월 x일" format
singleDate = parsedStartTime?.let {
formatDate(it)
}.orEmpty() // "x월 x일" format
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ data class TerminateBattleResponse(
)

fun TerminateBattleResponse.toDomainModel() = TerminateBattle(
message = this.message ?: ""
message = this.message.orEmpty()
)

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class UserResponse(
)

fun UserResponse.toDomainModel() = User(
id = this.userId ?: "",
nickName = this.nickName ?: "",
id = this.userId.orEmpty(),
nickName = this.nickName.orEmpty(),
profileImage = S3_URL.plus("/" + this.profileImage)
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class TestMemberRepository : MemberRepository {
override val userData: Flow<User>
get() = flowOf(
User(
id = userId ?: "",
nickName = userName ?: "",
profileImage = userProfile ?: ""
id = userId.orEmpty(),
nickName = userName.orEmpty(),
profileImage = userProfile.orEmpty()
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ fun DisplayMatchStatus(
val runnerInfo = matchUiState.runnerInfoData.runners.firstOrNull { it.id == item.id }

// 일치하는 RunnerInfo가 있으면 해당 이름과 프로필을 사용하고, 없으면 디폴트 텍스트를 사용
val runnerName = runnerInfo?.name ?: "이름 없음"
val runnerProfile = runnerInfo?.profile ?: ""
val runnerName = runnerInfo?.name.orEmpty()
val runnerProfile = runnerInfo?.profile.orEmpty()

MatchStatusItem(runnerName, runnerProfile, item.status)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class SignInViewModel @Inject constructor(
getSignInTokenUseCase(idToken)
.onSuccess { tokenData ->
saveTokensUseCase(
accessToken = tokenData.accessToken ?: "",
refreshToken = tokenData.refreshToken ?: ""
accessToken = tokenData.accessToken.orEmpty(),
refreshToken = tokenData.refreshToken.orEmpty()
)
updateSignInGoogleStateForSuccess() // 성공 시 상태 변경
}.onFailure { errorMessage, code ->
Expand Down

0 comments on commit bfe2b30

Please sign in to comment.