From bfe2b3090e0e56c7b4f3aa9e7d04e814e654c0f5 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Sun, 12 May 2024 00:13:06 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20orEmpty=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repository/ResultRepositoryImpl.kt | 3 ++- .../core/navigation/party/PartyNavigation.kt | 2 +- .../core/network/AuthAuthenticator.kt | 10 ++++---- .../core/network/model/BattleEventResponse.kt | 4 +-- .../model/response/BattleResultResponse.kt | 25 ++++++++++++++----- .../model/response/CancelMatchResponse.kt | 2 +- .../model/response/DeleteAccountResponse.kt | 2 +- .../model/response/MatchStatusResponse.kt | 2 +- .../model/response/PartyCodeResponse.kt | 2 +- .../response/RunningHistoryDetailResponse.kt | 8 +++--- .../model/response/SingleResultResponse.kt | 6 +++-- .../model/response/TerminateBattleResponse.kt | 3 +-- .../network/model/response/UserResponse.kt | 4 +-- .../repository/TestMemberRepository.kt | 6 ++--- .../feature/match/ui/MatchResultDialog.kt | 4 +-- .../feature/sign_in/SignInViewModel.kt | 4 +-- 16 files changed, 51 insertions(+), 36 deletions(-) diff --git a/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt b/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt index d61b94a7..fed9203e 100644 --- a/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt +++ b/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt @@ -42,7 +42,8 @@ class ResultRepositoryImpl @Inject constructor( } override suspend fun getSingleResults(): Result { - val singleId = singlePreferencesDataSource.getSingleId().first() ?: "" + val singleId = singlePreferencesDataSource + .getSingleId().first().orEmpty() return resultDataSource .getSingleResults(singleId) .toResultModel { it.toDomainModel() } diff --git a/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/party/PartyNavigation.kt b/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/party/PartyNavigation.kt index d4545a21..8f289c33 100644 --- a/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/party/PartyNavigation.kt +++ b/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/party/PartyNavigation.kt @@ -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, diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/AuthAuthenticator.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/AuthAuthenticator.kt index c1dc1686..f4a381a2 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/AuthAuthenticator.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/AuthAuthenticator.kt @@ -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 { @@ -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() } } diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/BattleEventResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/BattleEventResponse.kt index 92bc78bd..9e5b2883 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/BattleEventResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/BattleEventResponse.kt @@ -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) } diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/BattleResultResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/BattleResultResponse.kt index dfc6fb73..b888060b 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/BattleResultResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/BattleResultResponse.kt @@ -15,7 +15,7 @@ data class BattleResultResponse( @SerializedName("startTime") val startTime: String?, @SerializedName("targetDistance") - val targetDistance: Int? + val targetDistance: Int?, ) fun BattleResultResponse.toDomainModel(): BattleResult { @@ -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일" 형식화 ) } diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/CancelMatchResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/CancelMatchResponse.kt index bfe204be..8b1928e0 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/CancelMatchResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/CancelMatchResponse.kt @@ -9,5 +9,5 @@ data class CancelMatchResponse( ) fun CancelMatchResponse.toDomainModel() = CancelMatch( - message = this.message ?: "" + message = this.message.orEmpty() ) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/DeleteAccountResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/DeleteAccountResponse.kt index 92a98cf0..5b117d88 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/DeleteAccountResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/DeleteAccountResponse.kt @@ -9,5 +9,5 @@ data class DeleteAccountResponse( ) fun DeleteAccountResponse.toDomainModel() = DeleteAccount( - message = this.message ?: "" + message = this.message.orEmpty() ) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/MatchStatusResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/MatchStatusResponse.kt index 68edd7d4..4776932c 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/MatchStatusResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/MatchStatusResponse.kt @@ -9,5 +9,5 @@ data class MatchStatusResponse( ) fun MatchStatusResponse.toDomainModel() = MatchStatus( - message = this.message ?: "" + message = this.message.orEmpty() ) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/PartyCodeResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/PartyCodeResponse.kt index e929b38a..cc0b59d7 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/PartyCodeResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/PartyCodeResponse.kt @@ -9,5 +9,5 @@ data class PartyCodeResponse( ) fun PartyCodeResponse.toDomainModel() = PartyCode( - code = this.code ?: "" + code = this.code.orEmpty() ) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/RunningHistoryDetailResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/RunningHistoryDetailResponse.kt index 3ef297f1..0fdfd208 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/RunningHistoryDetailResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/RunningHistoryDetailResponse.kt @@ -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) @@ -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) @@ -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) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleResultResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleResultResponse.kt index 705beb2a..7e11f3ee 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleResultResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleResultResponse.kt @@ -13,7 +13,7 @@ data class SingleResultResponse( @SerializedName("runningTime") val runningTime: RunningTimeResponse, @SerializedName("records") - val records: List + val records: List, ) fun SingleResultResponse.toDomainModel(): SingleResult { @@ -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 ) } diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/TerminateBattleResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/TerminateBattleResponse.kt index ffdc71b7..fb5f4dca 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/TerminateBattleResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/TerminateBattleResponse.kt @@ -9,6 +9,5 @@ data class TerminateBattleResponse( ) fun TerminateBattleResponse.toDomainModel() = TerminateBattle( - message = this.message ?: "" + message = this.message.orEmpty() ) - diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/UserResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/UserResponse.kt index b992969d..b56ceeb3 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/UserResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/UserResponse.kt @@ -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) ) diff --git a/core/testing/src/main/java/online/partyrun/partyrunapplication/core/testing/repository/TestMemberRepository.kt b/core/testing/src/main/java/online/partyrun/partyrunapplication/core/testing/repository/TestMemberRepository.kt index 86695ca5..8a18d203 100644 --- a/core/testing/src/main/java/online/partyrun/partyrunapplication/core/testing/repository/TestMemberRepository.kt +++ b/core/testing/src/main/java/online/partyrun/partyrunapplication/core/testing/repository/TestMemberRepository.kt @@ -23,9 +23,9 @@ class TestMemberRepository : MemberRepository { override val userData: Flow get() = flowOf( User( - id = userId ?: "", - nickName = userName ?: "", - profileImage = userProfile ?: "" + id = userId.orEmpty(), + nickName = userName.orEmpty(), + profileImage = userProfile.orEmpty() ) ) diff --git a/feature/match/src/main/java/online/partyrun/partyrunapplication/feature/match/ui/MatchResultDialog.kt b/feature/match/src/main/java/online/partyrun/partyrunapplication/feature/match/ui/MatchResultDialog.kt index 76025d23..cc053992 100644 --- a/feature/match/src/main/java/online/partyrun/partyrunapplication/feature/match/ui/MatchResultDialog.kt +++ b/feature/match/src/main/java/online/partyrun/partyrunapplication/feature/match/ui/MatchResultDialog.kt @@ -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) } diff --git a/feature/sign_in/src/main/java/online/partyrun/partyrunapplication/feature/sign_in/SignInViewModel.kt b/feature/sign_in/src/main/java/online/partyrun/partyrunapplication/feature/sign_in/SignInViewModel.kt index 18e2b5f3..b68dd7fe 100644 --- a/feature/sign_in/src/main/java/online/partyrun/partyrunapplication/feature/sign_in/SignInViewModel.kt +++ b/feature/sign_in/src/main/java/online/partyrun/partyrunapplication/feature/sign_in/SignInViewModel.kt @@ -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 ->