From d59aadf6edee3f838cc6bb87406258f6b520204d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=ABsungmin?= Date: Tue, 12 Nov 2024 23:58:56 +0900 Subject: [PATCH] =?UTF-8?q?[mod]=20:=20#8=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20Toast=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/viewmodel/SignUpViewModel.kt | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/sopt/and/presentation/viewmodel/SignUpViewModel.kt b/app/src/main/java/org/sopt/and/presentation/viewmodel/SignUpViewModel.kt index 538f3d3..ddc3073 100644 --- a/app/src/main/java/org/sopt/and/presentation/viewmodel/SignUpViewModel.kt +++ b/app/src/main/java/org/sopt/and/presentation/viewmodel/SignUpViewModel.kt @@ -41,24 +41,40 @@ class SignUpViewModel @Inject constructor( } is SignUpContract.Event.OnSignUpButtonClicked -> { - if (currentState.username.isValidLength() && currentState.password.isValidLength() && - currentState.hobby.isValidLength() - ) { - viewModelScope.launch { - val result = userUseCase( - RegisterUserEntity( - currentState.username, - currentState.password, - currentState.hobby + val isUsernameValid = currentState.username.isValidLength() + val isPasswordValid = currentState.password.isValidLength() + val isHobbyValid = currentState.hobby.isValidLength() + + when { + !isUsernameValid -> { + setState(currentState.copy(status = SignUpContract.SignUpStatus.FAILURE)) + setEffect(SignUpContract.Effect.ShowToast("아이디는 8자 이상이어야 합니다.")) + } + !isPasswordValid -> { + setState(currentState.copy(status = SignUpContract.SignUpStatus.FAILURE)) + setEffect(SignUpContract.Effect.ShowToast("비밀번호는 8자 이상이어야 합니다.")) + } + !isHobbyValid -> { + setState(currentState.copy(status = SignUpContract.SignUpStatus.FAILURE)) + setEffect(SignUpContract.Effect.ShowToast("취미는 8자 이상이어야 합니다.")) + } + else -> { + viewModelScope.launch { + val result = userUseCase( + RegisterUserEntity( + currentState.username, + currentState.password, + currentState.hobby + ) ) - ) - result.onSuccess { - setState(currentState.copy(status = SignUpContract.SignUpStatus.SUCCESS)) - setEffect(SignUpContract.Effect.ShowToast("회원가입 성공")) - }.onFailure { exception -> - setState(currentState.copy(status = SignUpContract.SignUpStatus.FAILURE)) - setEffect(SignUpContract.Effect.ShowToast("회원가입 실패: ${exception.message}")) - Log.d("실패", "${exception.message}") + result.onSuccess { + setState(currentState.copy(status = SignUpContract.SignUpStatus.SUCCESS)) + setEffect(SignUpContract.Effect.ShowToast("회원가입 성공")) + }.onFailure { exception -> + setState(currentState.copy(status = SignUpContract.SignUpStatus.FAILURE)) + setEffect(SignUpContract.Effect.ShowToast("회원가입 실패: ${exception.message}")) + Log.d("실패", "${exception.message}") + } } } }