diff --git a/business/src/main/java/in/koreatech/business/feature/findpassword/changepassword/ChangePasswordViewModel.kt b/business/src/main/java/in/koreatech/business/feature/findpassword/changepassword/ChangePasswordViewModel.kt index 53efd7668..60a919a70 100644 --- a/business/src/main/java/in/koreatech/business/feature/findpassword/changepassword/ChangePasswordViewModel.kt +++ b/business/src/main/java/in/koreatech/business/feature/findpassword/changepassword/ChangePasswordViewModel.kt @@ -9,6 +9,7 @@ import `in`.koreatech.koin.domain.usecase.business.changepassword.ChangePassword import kotlinx.coroutines.launch import org.orbitmvi.orbit.Container import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -45,7 +46,7 @@ class ChangePasswordViewModel @Inject constructor( } } - fun insertPassword(password: String) = intent{ + fun insertPassword(password: String) = blockingIntent{ reduce { state.copy(password = password) } coincidePasswordReset() fillAllPasswords() diff --git a/business/src/main/java/in/koreatech/business/feature/findpassword/passwordauthentication/PasswordAuthenticationViewModel.kt b/business/src/main/java/in/koreatech/business/feature/findpassword/passwordauthentication/PasswordAuthenticationViewModel.kt index 0364673bf..1169378ea 100644 --- a/business/src/main/java/in/koreatech/business/feature/findpassword/passwordauthentication/PasswordAuthenticationViewModel.kt +++ b/business/src/main/java/in/koreatech/business/feature/findpassword/passwordauthentication/PasswordAuthenticationViewModel.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.launch import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -49,7 +50,7 @@ class PasswordAuthenticationViewModel @Inject constructor( } } - fun insertPhoneNumber(phoneNumber: String) = intent { + fun insertPhoneNumber(phoneNumber: String) = blockingIntent { reduce { state.copy( phoneNumber = phoneNumber, @@ -59,7 +60,7 @@ class PasswordAuthenticationViewModel @Inject constructor( } } - fun insertAuthCode(authCode: String) = intent { + fun insertAuthCode(authCode: String) = blockingIntent { reduce { state.copy( authenticationCode = authCode, diff --git a/business/src/main/java/in/koreatech/business/feature/insertstore/insertdetailinfo/InsertDetailInfoScreenViewmodel.kt b/business/src/main/java/in/koreatech/business/feature/insertstore/insertdetailinfo/InsertDetailInfoScreenViewmodel.kt index 8630153d7..05e6cba58 100644 --- a/business/src/main/java/in/koreatech/business/feature/insertstore/insertdetailinfo/InsertDetailInfoScreenViewmodel.kt +++ b/business/src/main/java/in/koreatech/business/feature/insertstore/insertdetailinfo/InsertDetailInfoScreenViewmodel.kt @@ -8,6 +8,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel import `in`.koreatech.business.feature.insertstore.insertmaininfo.InsertBasicInfoScreenState import org.orbitmvi.orbit.Container import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -60,21 +61,21 @@ class InsertDetailInfoScreenViewModel @Inject constructor( } } - fun onChangePhoneNumber(phoneNumber: String) = intent{ + fun onChangePhoneNumber(phoneNumber: String) = blockingIntent{ reduce { state.copy(storePhoneNumber = phoneNumber) } isDetailInfoValid() } - fun onChangeDeliveryFee(deliveryFee: String) = intent{ + fun onChangeDeliveryFee(deliveryFee: String) = blockingIntent{ reduce { state.copy(storeDeliveryFee = deliveryFee) } isDetailInfoValid() } - fun onChangeOtherInfo(otherInfo: String) = intent{ + fun onChangeOtherInfo(otherInfo: String) = blockingIntent{ reduce { state.copy(storeOtherInfo = otherInfo) } diff --git a/business/src/main/java/in/koreatech/business/feature/insertstore/insertmaininfo/InsertBasicInfoScreenViewModel.kt b/business/src/main/java/in/koreatech/business/feature/insertstore/insertmaininfo/InsertBasicInfoScreenViewModel.kt index c6cbb7ec5..bcc096858 100644 --- a/business/src/main/java/in/koreatech/business/feature/insertstore/insertmaininfo/InsertBasicInfoScreenViewModel.kt +++ b/business/src/main/java/in/koreatech/business/feature/insertstore/insertmaininfo/InsertBasicInfoScreenViewModel.kt @@ -10,6 +10,7 @@ import `in`.koreatech.koin.domain.usecase.presignedurl.GetMarketPreSignedUrlUseC import kotlinx.coroutines.launch import org.orbitmvi.orbit.Container import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -29,14 +30,14 @@ class InsertBasicInfoScreenViewModel @Inject constructor( getCategoryId(categoryId) } - fun insertStoreName(storeName: String) = intent { + fun insertStoreName(storeName: String) = blockingIntent { reduce { state.copy(storeName = storeName) } isBasicInfoValidate() } - fun insertStoreAddress(storeAddress: String) = intent{ + fun insertStoreAddress(storeAddress: String) = blockingIntent{ reduce { state.copy(storeAddress = storeAddress) } diff --git a/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupScreen.kt b/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupScreen.kt index 899bf1860..f6ce1f4ea 100644 --- a/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupScreen.kt +++ b/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupScreen.kt @@ -42,6 +42,7 @@ import `in`.koreatech.business.ui.theme.ColorUnarchived import `in`.koreatech.business.ui.theme.Gray1 import `in`.koreatech.business.ui.theme.Gray2 import `in`.koreatech.business.ui.theme.KOIN_ANDROIDTheme +import `in`.koreatech.koin.domain.error.owner.OwnerError import `in`.koreatech.koin.domain.state.signup.SignupContinuationState import org.orbitmvi.orbit.compose.collectAsState import org.orbitmvi.orbit.compose.collectSideEffect @@ -133,6 +134,7 @@ fun AccountSetupScreen( Column( modifier = Modifier + .fillMaxSize() .padding(horizontal = 24.dp) .verticalScroll(scrollState), verticalArrangement = Arrangement.Center, @@ -159,11 +161,17 @@ fun AccountSetupScreen( modifier = Modifier.width(203.dp), label = stringResource(id = R.string.enter_phone_number), textStyle = TextStyle.Default.copy(fontSize = 15.sp), - errorText = if (state.phoneNumberState is SignupContinuationState.Failed) state.phoneNumberState.message else stringResource( - R.string.error_network_unknown - ), + errorText = when (state.sendCodeError) { + OwnerError.ExistsPhoneNumberException -> stringResource( + id = R.string.error_account_duplicated + ) + OwnerError.NotValidPhoneNumberException -> stringResource( + id = R.string.error_invalid_phone_number + ) + else -> stringResource(id = R.string.error_network_unknown) + }, successText = stringResource(R.string.success_send_sms_code), - isError = state.phoneNumberState is SignupContinuationState.Failed, + isError = state.sendCodeError != null, isSuccess = state.phoneNumberState == SignupContinuationState.RequestedSmsValidation, ) @@ -171,17 +179,15 @@ fun AccountSetupScreen( .width(115.dp) .height(41.dp), shape = RoundedCornerShape(4.dp), - enabled = state.phoneNumber.isNotEmpty() && state.phoneNumberState !is SignupContinuationState.Failed, + enabled = state.phoneNumber.isNotEmpty() && state.phoneNumberState !is SignupContinuationState.RequestedSmsValidation, colors = ButtonDefaults.buttonColors( - backgroundColor = ColorPrimary, + backgroundColor = if(state.sendCodeError == null) ColorPrimary else ColorSecondary, contentColor = Color.White, disabledBackgroundColor = Gray2, disabledContentColor = Gray1, ), - onClick = { - viewModel.checkExistsAccount(state.phoneNumber) - - }) { + onClick = viewModel::checkExistsAccount + ) { Text( text = stringResource(id = R.string.send_authentication_code), fontWeight = Bold, @@ -274,14 +280,11 @@ fun AccountSetupScreen( errorText = stringResource(id = R.string.password_mismatch), isError = state.isPasswordConfirmError, ) - - - - - Spacer(modifier = Modifier.height(55.dp)) + Spacer(modifier = Modifier.weight(1f)) Button( modifier = Modifier .fillMaxWidth() + .padding(bottom = 24.dp) .height(44.dp), shape = RectangleShape, enabled = state.isButtonEnabled, diff --git a/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupState.kt b/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupState.kt index 5f2714ac2..874453784 100644 --- a/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupState.kt +++ b/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupState.kt @@ -11,5 +11,7 @@ data class AccountSetupState( val isPasswordConfirmError: Boolean = false, val verifyState : SignupContinuationState = SignupContinuationState.AvailablePhoneNumber, val phoneNumberState: SignupContinuationState = SignupContinuationState.AvailablePhoneNumber, + val verifyError:Throwable? = null, + val sendCodeError:Throwable? = null, val isButtonEnabled: Boolean = false ) \ No newline at end of file diff --git a/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupViewModel.kt b/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupViewModel.kt index 8d3d4ba30..fc9d17152 100644 --- a/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupViewModel.kt +++ b/business/src/main/java/in/koreatech/business/feature/signup/accountsetup/AccountSetupViewModel.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -88,20 +89,22 @@ class AccountSetupViewModel @Inject constructor( } } - fun onPhoneNumChanged(phoneNumber: String) = intent { + fun onPhoneNumChanged(phoneNumber: String) = blockingIntent { reduce { state.copy( phoneNumber = phoneNumber, - phoneNumberState = SignupContinuationState.AvailablePhoneNumber + phoneNumberState = SignupContinuationState.AvailablePhoneNumber, + sendCodeError = null, ) } } - fun onAuthCodeChanged(authCode: String) = intent { + fun onAuthCodeChanged(authCode: String) = blockingIntent { reduce { state.copy( authCode = authCode, - verifyState = SignupContinuationState.AvailablePhoneNumber + verifyState = SignupContinuationState.AvailablePhoneNumber, + verifyError = null, ) } } @@ -138,38 +141,42 @@ class AccountSetupViewModel @Inject constructor( } } - private fun sendSmsVerificationCode(phoneNumber: String) { - viewModelScope.launch { - sendSignupSmsCodeUseCase(phoneNumber).let { error -> - intent { + private fun sendSmsVerificationCode() { + intent { + viewModelScope.launch { + sendSignupSmsCodeUseCase(state.phoneNumber).onSuccess { reduce { state.copy( - phoneNumberState = if (error == null) SignupContinuationState.RequestedSmsValidation else SignupContinuationState.Failed( - error.message - ), + phoneNumberState = SignupContinuationState.RequestedSmsValidation, + sendCodeError = null, + ) + } + }.onFailure { + reduce { + state.copy( + sendCodeError = it, ) } - } } } } - fun checkExistsAccount(phoneNumber: String) { + fun checkExistsAccount() { viewModelScope.launch { - getOwnerExistsAccountUseCase(phoneNumber).onSuccess { - intent { + intent { + getOwnerExistsAccountUseCase(state.phoneNumber).onSuccess { reduce { - state.copy(phoneNumberState = SignupContinuationState.AvailablePhoneNumber) + state.copy( + phoneNumberState = SignupContinuationState.AvailablePhoneNumber, + sendCodeError = null, + ) } - sendSmsVerificationCode(phoneNumber) - } - - }.onFailure { - intent { + sendSmsVerificationCode() + }.onFailure { reduce { state.copy( - phoneNumberState = SignupContinuationState.Failed(it.message), + sendCodeError = it, ) } } diff --git a/business/src/main/java/in/koreatech/business/feature/signup/businessauth/BusinessAuthViewModel.kt b/business/src/main/java/in/koreatech/business/feature/signup/businessauth/BusinessAuthViewModel.kt index 3b339f5a7..ec0ffd44e 100644 --- a/business/src/main/java/in/koreatech/business/feature/signup/businessauth/BusinessAuthViewModel.kt +++ b/business/src/main/java/in/koreatech/business/feature/signup/businessauth/BusinessAuthViewModel.kt @@ -15,6 +15,7 @@ import `in`.koreatech.koin.domain.util.onFailure import `in`.koreatech.koin.domain.util.onSuccess import kotlinx.coroutines.launch import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -30,25 +31,25 @@ class BusinessAuthViewModel @Inject constructor( override val container = container(BusinessAuthState()) - fun onNameChanged(name: String) = intent { + fun onNameChanged(name: String) = blockingIntent { reduce { state.copy(name = name) } } - fun onShopNameChanged(storeName: String) = intent { + fun onShopNameChanged(storeName: String) = blockingIntent { reduce { state.copy(shopName = storeName) } } - fun onShopIdChanged(shopId: Int?) = intent { + fun onShopIdChanged(shopId: Int?) = blockingIntent { reduce { state.copy(shopId = shopId) } } - fun onStoreNumberChanged(storeNumber: String) = intent { + fun onStoreNumberChanged(storeNumber: String) = blockingIntent { reduce { state.copy( shopNumber = storeNumber, diff --git a/business/src/main/java/in/koreatech/business/feature/signup/businessauth/SearchStoreViewModel.kt b/business/src/main/java/in/koreatech/business/feature/signup/businessauth/SearchStoreViewModel.kt index 1cd0c236e..33adc4833 100644 --- a/business/src/main/java/in/koreatech/business/feature/signup/businessauth/SearchStoreViewModel.kt +++ b/business/src/main/java/in/koreatech/business/feature/signup/businessauth/SearchStoreViewModel.kt @@ -7,6 +7,7 @@ import `in`.koreatech.koin.domain.usecase.business.SearchStoresUseCase import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -30,7 +31,7 @@ class SearchStoreViewModel @Inject constructor( } } - fun onSearchChanged(search: String) = intent { + fun onSearchChanged(search: String) = blockingIntent { reduce { state.copy(search = search) } diff --git a/business/src/main/java/in/koreatech/business/feature/signup/checkterm/CheckTermScreen.kt b/business/src/main/java/in/koreatech/business/feature/signup/checkterm/CheckTermScreen.kt index 113098fdb..26721e314 100644 --- a/business/src/main/java/in/koreatech/business/feature/signup/checkterm/CheckTermScreen.kt +++ b/business/src/main/java/in/koreatech/business/feature/signup/checkterm/CheckTermScreen.kt @@ -15,6 +15,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll @@ -137,7 +138,7 @@ fun CheckTermScreen( } Column( - modifier = Modifier + modifier = Modifier.fillMaxSize() .padding(horizontal = 24.dp) .verticalScroll(scrollState), verticalArrangement = Arrangement.Center, @@ -260,11 +261,11 @@ fun CheckTermScreen( Text(text = stringResource(R.string.term_2), fontSize = 10.sp, color = Color.Black) } - Spacer(modifier = Modifier.height(50.dp)) - + Spacer(modifier = Modifier.weight(1f)) Button( modifier = modifier .fillMaxWidth() + .padding(bottom = 24.dp) .height(44.dp), onClick = { viewModel.onNextButtonClicked() }, shape = RoundedCornerShape(4.dp), diff --git a/business/src/main/java/in/koreatech/business/feature/signup/completesignup/CompleteSignupScreen.kt b/business/src/main/java/in/koreatech/business/feature/signup/completesignup/CompleteSignupScreen.kt index a0fcf59a4..314d31eb0 100644 --- a/business/src/main/java/in/koreatech/business/feature/signup/completesignup/CompleteSignupScreen.kt +++ b/business/src/main/java/in/koreatech/business/feature/signup/completesignup/CompleteSignupScreen.kt @@ -150,10 +150,10 @@ fun CompleteSignupScreen( fontSize = 16.sp, color = ColorDescription, ) - - Spacer(modifier = Modifier.height(51.dp)) + Spacer(modifier = Modifier.weight(1f)) Button(modifier = Modifier .fillMaxWidth() + .padding(bottom = 24.dp) .height(44.dp), shape = RoundedCornerShape(4.dp), colors = ButtonDefaults.buttonColors( diff --git a/business/src/main/java/in/koreatech/business/feature/store/modifyinfo/ModifyInfoViewModel.kt b/business/src/main/java/in/koreatech/business/feature/store/modifyinfo/ModifyInfoViewModel.kt index c1183cb1b..4370b15c7 100644 --- a/business/src/main/java/in/koreatech/business/feature/store/modifyinfo/ModifyInfoViewModel.kt +++ b/business/src/main/java/in/koreatech/business/feature/store/modifyinfo/ModifyInfoViewModel.kt @@ -13,6 +13,7 @@ import `in`.koreatech.koin.domain.usecase.business.store.ModifyShopInfoUseCase import `in`.koreatech.koin.domain.usecase.owner.GetPresignedUrlUseCase import kotlinx.coroutines.launch import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -131,32 +132,31 @@ class ModifyInfoViewModel @Inject constructor( } } - fun onStoreNameChanged(storeName: String) = intent { + fun onStoreNameChanged(storeName: String) = blockingIntent { reduce { state.copy(storeInfo = state.storeInfo.copy(name = storeName)) } } - fun onPhoneNumberChanged(phone: String) = intent { + fun onPhoneNumberChanged(phone: String) = blockingIntent { reduce { state.copy(storeInfo = state.storeInfo.copy(phone = phone)) } } - fun onAddressChanged(address: String) = intent { - + fun onAddressChanged(address: String) = blockingIntent { reduce { state.copy(storeInfo = state.storeInfo.copy(address = address)) } } - fun onDeliveryPriceChanged(price: Int) = intent { + fun onDeliveryPriceChanged(price: Int) = blockingIntent { reduce { state.copy(storeInfo = state.storeInfo.copy(deliveryPrice = price)) } } - fun onDescriptionChanged(description: String) = intent { + fun onDescriptionChanged(description: String) = blockingIntent { reduce { state.copy(storeInfo = state.storeInfo.copy(description = description)) } diff --git a/business/src/main/java/in/koreatech/business/feature/storemenu/modifymenu/modifymenu/ModifyMenuViewModel.kt b/business/src/main/java/in/koreatech/business/feature/storemenu/modifymenu/modifymenu/ModifyMenuViewModel.kt index deab9dfda..7a9adfe64 100644 --- a/business/src/main/java/in/koreatech/business/feature/storemenu/modifymenu/modifymenu/ModifyMenuViewModel.kt +++ b/business/src/main/java/in/koreatech/business/feature/storemenu/modifymenu/modifymenu/ModifyMenuViewModel.kt @@ -19,6 +19,7 @@ import `in`.koreatech.koin.domain.usecase.presignedurl.GetMarketPreSignedUrlUseC import kotlinx.coroutines.launch import org.orbitmvi.orbit.Container import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -238,7 +239,7 @@ class ModifyMenuViewModel @Inject constructor( } } - fun changeMenuName(menuName: String) = intent{ + fun changeMenuName(menuName: String) = blockingIntent{ reduce { state.copy( menuName = menuName @@ -247,7 +248,7 @@ class ModifyMenuViewModel @Inject constructor( } fun changeMenuPrice(price: String){ - intent{ + blockingIntent{ reduce { state.copy(menuPrice = price) } @@ -255,7 +256,7 @@ class ModifyMenuViewModel @Inject constructor( } fun changeDetailMenuServing(index: Int, serving: String){ - intent{ + blockingIntent{ if (index in state.menuOptionPrice.indices) { reduce { val newMenuPrice = state.menuOptionPrice.toMutableList() @@ -267,7 +268,7 @@ class ModifyMenuViewModel @Inject constructor( } fun changeDetailMenuPrice(index: Int, price: String){ - intent{ + blockingIntent{ if (index in state.menuOptionPrice.indices) { reduce { val newMenuPrice = state.menuOptionPrice.toMutableList() @@ -334,7 +335,7 @@ class ModifyMenuViewModel @Inject constructor( } } - fun changeMenuDetail(menuDetail: String) = intent{ + fun changeMenuDetail(menuDetail: String) = blockingIntent{ reduce { state.copy( description = menuDetail diff --git a/business/src/main/java/in/koreatech/business/feature/storemenu/registermenu/registermenu/RegisterMenuViewModel.kt b/business/src/main/java/in/koreatech/business/feature/storemenu/registermenu/registermenu/RegisterMenuViewModel.kt index 40af8b61e..faffa8cb7 100644 --- a/business/src/main/java/in/koreatech/business/feature/storemenu/registermenu/registermenu/RegisterMenuViewModel.kt +++ b/business/src/main/java/in/koreatech/business/feature/storemenu/registermenu/registermenu/RegisterMenuViewModel.kt @@ -16,6 +16,7 @@ import `in`.koreatech.koin.domain.usecase.business.menu.RegisterMenuUseCase import `in`.koreatech.koin.domain.usecase.presignedurl.GetMarketPreSignedUrlUseCase import kotlinx.coroutines.launch import org.orbitmvi.orbit.ContainerHost +import org.orbitmvi.orbit.syntax.simple.blockingIntent import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce @@ -204,7 +205,7 @@ class RegisterMenuViewModel @Inject constructor( } } - fun changeMenuName(menuName: String) = intent{ + fun changeMenuName(menuName: String) = blockingIntent{ reduce { state.copy( menuName = menuName @@ -213,7 +214,7 @@ class RegisterMenuViewModel @Inject constructor( } fun changeMenuPrice(price: String){ - intent{ + blockingIntent{ reduce { state.copy(menuPrice = price) } @@ -221,7 +222,7 @@ class RegisterMenuViewModel @Inject constructor( } fun changeDetailMenuServing(index: Int, serving: String){ - intent{ + blockingIntent{ if (index in state.menuOptionPrice.indices) { reduce { val newMenuPrice = state.menuOptionPrice.toMutableList() @@ -233,7 +234,7 @@ class RegisterMenuViewModel @Inject constructor( } fun changeDetailMenuPrice(index: Int, price: String){ - intent{ + blockingIntent{ if (index in state.menuOptionPrice.indices) { reduce { val newMenuPrice = state.menuOptionPrice.toMutableList() @@ -298,7 +299,7 @@ class RegisterMenuViewModel @Inject constructor( } } - fun changeMenuDetail(menuDetail: String) = intent{ + fun changeMenuDetail(menuDetail: String) = blockingIntent{ reduce { state.copy( description = menuDetail diff --git a/data/src/main/java/in/koreatech/koin/data/repository/OwnerSignupRepositoryImpl.kt b/data/src/main/java/in/koreatech/koin/data/repository/OwnerSignupRepositoryImpl.kt index 8ba0af99a..25a56e31b 100644 --- a/data/src/main/java/in/koreatech/koin/data/repository/OwnerSignupRepositoryImpl.kt +++ b/data/src/main/java/in/koreatech/koin/data/repository/OwnerSignupRepositoryImpl.kt @@ -1,13 +1,12 @@ package `in`.koreatech.koin.data.repository import `in`.koreatech.koin.data.mapper.httpExceptionMapper -import `in`.koreatech.koin.data.mapper.safeApiCall import `in`.koreatech.koin.data.request.owner.OwnerVerificationEmailRequest import `in`.koreatech.koin.data.request.owner.VerificationSmsRequest import `in`.koreatech.koin.data.source.local.SignupTermsLocalDataSource import `in`.koreatech.koin.data.source.remote.OwnerRemoteDataSource +import `in`.koreatech.koin.domain.error.owner.OwnerError import `in`.koreatech.koin.domain.repository.OwnerSignupRepository -import org.json.JSONObject import retrofit2.HttpException import javax.inject.Inject @@ -43,31 +42,32 @@ class OwnerSignupRepositoryImpl @Inject constructor( override suspend fun requestSmsVerificationCode( phoneNumber: String - ): Pair, String?> { + ): Result { return try { - Pair(safeApiCall { - ownerRemoteDataSource.postVerificationSms( - VerificationSmsRequest( - phoneNumber = phoneNumber - ) + ownerRemoteDataSource.postVerificationSms( + VerificationSmsRequest( + phoneNumber = phoneNumber ) - }, null) - - } catch (e: HttpException) { - if (e.code() == 500) { - val errorBody = e.response()?.errorBody()?.string() - val message = errorBody?.let { JSONObject(it).getString("message") } - Pair(Result.failure(e), message) - } else { - Pair(Result.failure(e), null) - } + ) + Result.success(Unit) } catch (t: Throwable) { - Pair(Result.failure(t), null) + Result.failure(t) } } - override suspend fun getExistsAccount(phoneNumber: String) { - return ownerRemoteDataSource.checkExistsAccount(phoneNumber) + override suspend fun getExistsAccount(phoneNumber: String): Result { + return try { + ownerRemoteDataSource.checkExistsAccount(phoneNumber) + Result.success(Unit) + } catch (e: HttpException) { + if (e.code() == 400) + throw OwnerError.NotValidPhoneNumberException + else if (e.code() == 409) + throw OwnerError.ExistsPhoneNumberException + else throw e + } catch (t: Throwable) { + Result.failure(t) + } } } diff --git a/domain/src/main/java/in/koreatech/koin/domain/error/owner/OwnerError.kt b/domain/src/main/java/in/koreatech/koin/domain/error/owner/OwnerError.kt index b5a6ae520..e1fcd0f5a 100644 --- a/domain/src/main/java/in/koreatech/koin/domain/error/owner/OwnerError.kt +++ b/domain/src/main/java/in/koreatech/koin/domain/error/owner/OwnerError.kt @@ -12,5 +12,6 @@ sealed class OwnerError { object IncorrectParaMeter: IllegalAccessException() object NotValidPhoneNumberException: IllegalAccessException() object NotExistsPhoneNumberException: IllegalAccessException() + object ExistsPhoneNumberException: IllegalAccessException() } \ No newline at end of file diff --git a/domain/src/main/java/in/koreatech/koin/domain/repository/OwnerSignupRepository.kt b/domain/src/main/java/in/koreatech/koin/domain/repository/OwnerSignupRepository.kt index 7f81f706f..91d44dafb 100644 --- a/domain/src/main/java/in/koreatech/koin/domain/repository/OwnerSignupRepository.kt +++ b/domain/src/main/java/in/koreatech/koin/domain/repository/OwnerSignupRepository.kt @@ -1,7 +1,5 @@ package `in`.koreatech.koin.domain.repository -import `in`.koreatech.koin.domain.model.error.ErrorHandler - interface OwnerSignupRepository { suspend fun getPrivacyTermText(): String suspend fun getKoinTermText(): String @@ -12,9 +10,9 @@ interface OwnerSignupRepository { suspend fun requestSmsVerificationCode( phoneNumber: String, - ): Pair,String?> + ): Result suspend fun getExistsAccount( phoneNumber: String - ) + ): Result } \ No newline at end of file diff --git a/domain/src/main/java/in/koreatech/koin/domain/usecase/business/GetOwnerExistsAccountUseCase.kt b/domain/src/main/java/in/koreatech/koin/domain/usecase/business/GetOwnerExistsAccountUseCase.kt index 0fba595f8..a9a49a077 100644 --- a/domain/src/main/java/in/koreatech/koin/domain/usecase/business/GetOwnerExistsAccountUseCase.kt +++ b/domain/src/main/java/in/koreatech/koin/domain/usecase/business/GetOwnerExistsAccountUseCase.kt @@ -7,17 +7,14 @@ import javax.inject.Inject class GetOwnerExistsAccountUseCase @Inject constructor( private val ownerSignupRepository: OwnerSignupRepository, - private val ownerError: OwnerErrorHandler, ) { suspend operator fun invoke( phoneNumber: String, - ): Pair { + ): Result{ return try { - ownerSignupRepository.getExistsAccount(phoneNumber).let { - Pair(false, null) - } + ownerSignupRepository.getExistsAccount(phoneNumber) } catch (t: Throwable) { - ownerError.handleExistsAccountError(t) + Result.failure(t) } } } diff --git a/domain/src/main/java/in/koreatech/koin/domain/usecase/business/SendSignupSmsCodeUseCase.kt b/domain/src/main/java/in/koreatech/koin/domain/usecase/business/SendSignupSmsCodeUseCase.kt index fb72ffe81..3434e9d0b 100644 --- a/domain/src/main/java/in/koreatech/koin/domain/usecase/business/SendSignupSmsCodeUseCase.kt +++ b/domain/src/main/java/in/koreatech/koin/domain/usecase/business/SendSignupSmsCodeUseCase.kt @@ -7,16 +7,14 @@ import javax.inject.Inject class SendSignupSmsCodeUseCase @Inject constructor( private val ownerSignupRepository: OwnerSignupRepository, - private val ownerErrorHandler: OwnerErrorHandler, ) { suspend operator fun invoke( phoneNumber: String, - ): ErrorHandler? { + ): Result { return try { ownerSignupRepository.requestSmsVerificationCode(phoneNumber) - null } catch (t: Throwable) { - ownerErrorHandler.handleSendSmsError(t) + Result.failure(t) } } } \ No newline at end of file