Skip to content

Commit

Permalink
Merge pull request #150 from BCSDLab/feature/#149-check-exist-email
Browse files Browse the repository at this point in the history
Feature/#149 check exist email
  • Loading branch information
wnehdals authored Jan 26, 2024
2 parents 628a8e3 + 104a585 commit 549414d
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 48 deletions.
6 changes: 6 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 36 additions & 18 deletions app/src/main/java/com/jjbaksa/jjbaksa/ui/signup/SignUpFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import com.google.android.material.internal.TextWatcherAdapter
import com.jjbaksa.domain.enums.SignUpAlertEnum
import com.jjbaksa.domain.enums.SignUpAlertEnum.EMAIL_ALREADY_EXIST
import com.jjbaksa.domain.enums.SignUpAlertEnum.EMAIL_NOT_FOUND
import com.jjbaksa.domain.enums.SignUpAlertEnum.NEED_ID_CHECK
import com.jjbaksa.domain.enums.SignUpAlertEnum.PASSWORD_NOT_MATCH
Expand All @@ -16,7 +17,6 @@ import com.jjbaksa.jjbaksa.R
import com.jjbaksa.jjbaksa.base.BaseFragment
import com.jjbaksa.jjbaksa.databinding.FragmentSignUpBinding
import com.jjbaksa.jjbaksa.dialog.ConfirmDialog
import com.jjbaksa.jjbaksa.ui.findpassword.FindPasswordResetFragment
import com.jjbaksa.jjbaksa.util.RegexUtil.isPasswordRuleMatch
import com.jjbaksa.jjbaksa.ui.signup.viewmodel.SignUpViewModel
import com.jjbaksa.jjbaksa.util.KeyboardProvider
Expand Down Expand Up @@ -167,27 +167,41 @@ class SignUpFragment : BaseFragment<FragmentSignUpBinding>() {
binding.buttonSignUpNext.setOnClickListener {
checkInputsCorrect()
if (!signUpViewModel.uiState.value?.isAlertShown!!) {
signUpViewModel.postUserEmailCheck(signUpViewModel.email)
if (signUpViewModel.uiState.value?.isIdChecked == true) {
ConfirmDialog(
getString(R.string.sign_up_title_text),
getString(R.string.sign_up_content_text),
getString(R.string.confirm),
{
findNavController().navigate(R.id.action_nav_graph_move_to_welcome)
dismissDialog()
signUpViewModel.signUpRequest(
{
if (signUpViewModel.uiState.value?.isIdChecked == true && signUpViewModel.isSignUpSuccess) {
signUpViewModel.postUserEmailCheck(signUpViewModel.email)
ConfirmDialog(
getString(R.string.sign_up_title_text),
getString(R.string.sign_up_content_text),
getString(R.string.confirm),
{
findNavController().navigate(R.id.action_nav_graph_move_to_welcome)
dismissDialog()
}
).show(parentFragmentManager, DIALOG_TAG)
} else {
signUpViewModel.updateAlertType(NEED_ID_CHECK)
signUpViewModel.updateAlertState(true)
}
).show(parentFragmentManager, FindPasswordResetFragment.DIALOG_TAG)
} else {
signUpViewModel.updateAlertType(NEED_ID_CHECK)
}
) {
KeyboardProvider(requireContext()).run {
hideKeyboard(binding.jEditTextSignUpId)
hideKeyboard(binding.jEditTextSignUpEmail)
hideKeyboard(binding.jEditTextSignUpPassword)
hideKeyboard(binding.jEditTextSignUpPasswordConfirm)
}
showSnackBar(it)
signUpViewModel.updateAlertState(true)
signUpViewModel.isSignUpSuccess = false
}
}
}
}

private fun dismissDialog() {
val dialogFragment = parentFragmentManager.findFragmentByTag(FindPasswordResetFragment.DIALOG_TAG)
val dialogFragment = parentFragmentManager.findFragmentByTag(DIALOG_TAG)
if (dialogFragment is DialogFragment) {
dialogFragment.dismiss()
}
Expand All @@ -198,11 +212,10 @@ class SignUpFragment : BaseFragment<FragmentSignUpBinding>() {
setAlert(it.alertType)
}

signUpViewModel.userEmailCheckState.observe(viewLifecycleOwner) {
if (it) {
findNavController().navigate(R.id.action_nav_graph_move_to_welcome)
signUpViewModel.login.observe(viewLifecycleOwner) {
if (it.isSuccess) {
} else {
binding.buttonSignUpNext.isEnabled = false
showSnackBar(it.errorMessage)
}
}
}
Expand Down Expand Up @@ -232,6 +245,7 @@ class SignUpFragment : BaseFragment<FragmentSignUpBinding>() {
PASSWORD_RULE_NOT_MATCH -> context?.getString(R.string.password_rule_not_match)
PASSWORD_NOT_MATCH -> context?.getString(R.string.password_not_match)
NEED_ID_CHECK -> context?.getString(R.string.need_id_check)
EMAIL_ALREADY_EXIST -> context?.getString(R.string.email_already_exist)
}

return alertMsg
Expand Down Expand Up @@ -270,4 +284,8 @@ class SignUpFragment : BaseFragment<FragmentSignUpBinding>() {
}
}
}

companion object {
private const val DIALOG_TAG = "DIALOG_TAG"
}
}
33 changes: 19 additions & 14 deletions app/src/main/java/com/jjbaksa/jjbaksa/ui/signup/WelcomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.jjbaksa.jjbaksa.ui.signup

import android.annotation.SuppressLint
import android.os.Bundle
import android.text.Editable
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.activityViewModels
import com.google.android.material.internal.TextWatcherAdapter
Expand All @@ -15,18 +17,26 @@ import dagger.hilt.android.AndroidEntryPoint
class WelcomeFragment : BaseFragment<FragmentWelcomeBinding>() {

private val signUpViewModel: SignUpViewModel by activityViewModels()
protected override var onBackPressedCallBack: OnBackPressedCallback? = object :
OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
activity?.finish()
}
}
override val layoutId: Int
get() = R.layout.fragment_welcome
override fun initView() {}

override fun initEvent() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

requireActivity().onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
activity?.finish()
}
}
)
onBackPressedCallBack?.let { requireActivity().onBackPressedDispatcher.addCallback(it) }
}

override fun onDetach() {
super.onDetach()
}
override fun initEvent() {

with(binding) {

Expand All @@ -44,13 +54,8 @@ class WelcomeFragment : BaseFragment<FragmentWelcomeBinding>() {
)

buttonWelcomeComplete.setOnClickListener {

signUpViewModel.signUpRequest()
signUpViewModel.isSignUpSuccess.observe(viewLifecycleOwner) {
if (it) {
activity?.finish()
}
}
signUpViewModel.setNewNickname(binding.jEditTextWelcomeName.text)
activity?.finish()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.jjbaksa.jjbaksa.ui.signup.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.jjbaksa.domain.base.RespResult
import com.jjbaksa.domain.enums.SignUpAlertEnum
import com.jjbaksa.domain.model.user.Login
import com.jjbaksa.domain.model.user.SignUpReq
import com.jjbaksa.domain.usecase.CheckAccountAvailableUseCase
import com.jjbaksa.domain.usecase.SignUpUseCase
Expand All @@ -23,12 +23,8 @@ class SignUpViewModel @Inject constructor(
private val userUseCase: UserUseCase
) : BaseViewModel() {

private val _isSignUpSuccess = MutableLiveData<Boolean>()
private val _userEmailCheckState = SingleLiveEvent<Boolean>()
val userEmailCheckState: SingleLiveEvent<Boolean> get() = _userEmailCheckState

val isSignUpSuccess: LiveData<Boolean>
get() = _isSignUpSuccess
private val _login = SingleLiveEvent<Login>()
val login: SingleLiveEvent<Login> get() = _login

val userEmail = MutableLiveData<String>("")
private val _uiState = SingleLiveEvent<SignUpUIState>()
Expand All @@ -40,6 +36,8 @@ class SignUpViewModel @Inject constructor(
var passwordCheck: String = ""
var nickname: String = ""

var isSignUpSuccess = true

init {
_uiState.value = SignUpUIState()
}
Expand Down Expand Up @@ -79,13 +77,14 @@ class SignUpViewModel @Inject constructor(
_uiState.value = _uiState.value?.copy(alertType = newAlertType)
}

fun signUpRequest() {
fun signUpRequest(onSuccess: () -> Unit, onError: (String) -> Unit) {
val signUpReq = SignUpReq(id, email, nickname, password)
viewModelScope.launch {
runCatching {
signUpUseCase(signUpReq)
isSignUpSuccess = true
signUpUseCase(signUpReq, onError)
}.onSuccess {
_isSignUpSuccess.value = true
onSuccess()
}.onFailure {
// Handle sign up fail throwable
}
Expand All @@ -97,9 +96,15 @@ class SignUpViewModel @Inject constructor(
viewModelScope.launch(ceh) {
userUseCase.postUserEmailCheck(email).collect {
it.onSuccess {
_userEmailCheckState.value = it.isSuccess
_login.value = it
}
}
}
}

fun setNewNickname(nickname: String) {
viewModelScope.launch(ceh) {
userUseCase.setNewNickname(nickname)
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,5 @@
<string name="last_review_date">마지막 리뷰 %s</string>
<string name="schedule">%s ~ %s</string>
<string name="id_format_not_match">올바른 형식의 아이디가 아닙니다.</string>
<string name="email_already_exist">이미 회원가입된 이메일입니다.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,13 @@ class UserRepositoryImpl @Inject constructor(
)
}

override suspend fun postSignUp(signUpReq: SignUpReq): SignUpResp? {
override suspend fun postSignUp(signUpReq: SignUpReq, onError: (String) -> Unit): SignUpResp? {
val resp = userRemoteDataSource.postSignUp(signUpReq)
if (!resp.isSuccessful) {
val errorBodyJson = resp.errorBody()!!.string()
val errorBody = RespMapper.errorMapper(errorBodyJson)
onError(errorBody.errorMessage)
}
return resp.body()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.jjbaksa.domain.enums

enum class SignUpAlertEnum {
EMAIL_NOT_FOUND, PASSWORD_RULE_NOT_MATCH, PASSWORD_NOT_MATCH, NEED_ID_CHECK
EMAIL_NOT_FOUND, PASSWORD_RULE_NOT_MATCH, PASSWORD_NOT_MATCH, NEED_ID_CHECK, EMAIL_ALREADY_EXIST
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface UserRepository {
onError: (String) -> Unit
): Flow<Result<Boolean>>

suspend fun postSignUp(signUpReq: SignUpReq): SignUpResp?
suspend fun postSignUp(signUpReq: SignUpReq, onError: (String) -> Unit): SignUpResp?
suspend fun checkAccountAvailable(account: String): RespResult<Boolean>
suspend fun postUserWithdrawReason(
withdrawalReason: WithdrawalReasonReq,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import javax.inject.Inject
class SignUpUseCase @Inject constructor(
private val userRepository: UserRepository
) {
suspend operator fun invoke(signUpReq: SignUpReq): SignUpResp? {
return userRepository.postSignUp(signUpReq)
suspend operator fun invoke(signUpReq: SignUpReq, onError: (String) -> Unit): SignUpResp? {
return userRepository.postSignUp(signUpReq, onError)
}
}

0 comments on commit 549414d

Please sign in to comment.