Skip to content

Commit

Permalink
refactor: onError() suspend로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
rhkrwngud445 committed Mar 30, 2024
1 parent 2a7411f commit ef5c4c1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DefaultUserRepository @Inject constructor(
override fun updateProfile(
nickname: String,
profileImage: String,
onError: (WithPeaceError) -> Unit,
onError: suspend (WithPeaceError) -> Unit,
): Flow<Unit> = flow {
val imagePart = getImagePart(profileImage)
userService.updateProfile(
Expand All @@ -67,7 +67,7 @@ class DefaultUserRepository @Inject constructor(
}
}

override fun updateNickname(nickname: String, onError: (WithPeaceError) -> Unit): Flow<Unit> =
override fun updateNickname(nickname: String, onError: suspend (WithPeaceError) -> Unit): Flow<Unit> =
flow {
userService.updateNickname(NicknameRequest(nickname)).suspendMapSuccess {
emit(Unit)
Expand All @@ -81,7 +81,7 @@ class DefaultUserRepository @Inject constructor(

override fun updateProfileImage(
profileImage: String,
onError: (WithPeaceError) -> Unit,
onError: suspend (WithPeaceError) -> Unit,
): Flow<Unit> = flow {
val imagePart = getImagePart(profileImage)
userService.updateImage(imagePart).suspendMapSuccess {
Expand All @@ -96,7 +96,7 @@ class DefaultUserRepository @Inject constructor(

override fun verifyNicknameDuplicated(
nickname: Nickname,
onError: (WithPeaceError) -> Unit,
onError: suspend (WithPeaceError) -> Unit,
): Flow<Unit> = flow {
userService.isNicknameDuplicate(nickname.value).suspendMapSuccess {
if (this.data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.withpeace.withpeace.core.domain.repository

import com.withpeace.withpeace.core.domain.model.WithPeaceError
import com.withpeace.withpeace.core.domain.model.profile.ChangingProfileInfo
import com.withpeace.withpeace.core.domain.model.profile.Nickname
import com.withpeace.withpeace.core.domain.model.profile.ProfileInfo
import kotlinx.coroutines.flow.Flow
Expand All @@ -15,21 +14,21 @@ interface UserRepository {

fun updateProfileImage(
profileImage: String,
onError: (WithPeaceError) -> Unit,
onError: suspend (WithPeaceError) -> Unit,
): Flow<Unit>

fun updateNickname(
nickname: String,
onError: (WithPeaceError) -> Unit,
onError: suspend (WithPeaceError) -> Unit,
): Flow<Unit>

fun updateProfile(
nickname: String, profileImage: String,
onError: (WithPeaceError) -> Unit,
onError: suspend (WithPeaceError) -> Unit,
): Flow<Unit>

fun verifyNicknameDuplicated(
nickname: Nickname,
onError: (WithPeaceError) -> Unit,
onError: suspend (WithPeaceError) -> Unit,
): Flow<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UpdateProfileUseCase @Inject constructor(
operator fun invoke(
beforeProfile: ChangingProfileInfo,
afterProfile: ChangingProfileInfo,
onError: (WithPeaceError) -> Unit,
onError: suspend (WithPeaceError) -> Unit,
): Flow<Unit> {
return when (ProfileChangingStatus.getStatus(beforeProfile, afterProfile)) {
ProfileChangingStatus.AllChanging -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import javax.inject.Inject
class VerifyNicknameUseCase @Inject constructor(
private val userRepository: UserRepository,
) {
operator fun invoke(nickname: String, onError: (WithPeaceError) -> Unit): Flow<Unit> {
operator fun invoke(nickname: String, onError: suspend (WithPeaceError) -> Unit): Flow<Unit> {
if (!Nickname.verifyNickname(nickname)) {
onError(WithPeaceError.GeneralError(code = 1))
return flow { }
return flow { onError(WithPeaceError.GeneralError(code = 1)) }
}
return userRepository.verifyNicknameDuplicated(Nickname.create(nickname), onError = onError)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class ProfileEditorViewModel @Inject constructor(
viewModelScope.launch {
verifyNicknameUseCase(
onError = { error ->
this.launch {
_profileEditUiEvent.send(
when (error) {
is WithPeaceError.GeneralError -> {
Expand All @@ -94,11 +93,9 @@ class ProfileEditorViewModel @Inject constructor(
else -> ProfileEditUiEvent.ShowFailure
}
}

else -> ProfileEditUiEvent.ShowFailure
},
)
}
},
nickname = (profileEditUiState.value as ProfileEditUiState.Editing).profileInfo.nickname,
).collect {
Expand Down

0 comments on commit ef5c4c1

Please sign in to comment.