Skip to content

Commit

Permalink
[Feat] #17 - 회원가입 아이디 중복확인
Browse files Browse the repository at this point in the history
- 서버 DB에 중복확인 요청을 보내는 코드 작성
- 인증번호 요청하는 코드는 작업 예정
- response의 data가 아닌, message를 필요로 하는 경우가 있어서 cazaitResponse가 없는 normalProcessCall 만듬. 이 과정에서 오류가 있는 듯
  • Loading branch information
WooBinHam committed Aug 17, 2023
1 parent 1dfaa55 commit 656f1f0
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cazait.data.repository

import android.util.Log
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
Expand Down Expand Up @@ -52,7 +53,7 @@ class UserRepositoryImpl @Inject constructor(
TODO("Not yet implemented")
}

override suspend fun checkPhoneNumDB(
override fun checkPhoneNumDB(
phoneNumber: String,
isExist: String
): Flow<Result<String>> {
Expand All @@ -67,19 +68,22 @@ class UserRepositoryImpl @Inject constructor(
}
}

override suspend fun checkUserIdDB(userId: String, isExist: String): Flow<Result<String>> {
override fun checkUserIdDB(userId: String, isExist: String): Flow<Result<String>> {
return flow {
Log.d("UserRepository IdDup", "도달했나?")
userRemoteData.postCheckUserId(CheckUserIdReq(userId, isExist)).map {
it.onSuccess { res ->
Log.d("UserRepository IdDup", res.toString())
emit(Result.success(res.message))
}.onFailure { t ->
Log.d("UserRepository IdDup", t.toString())
emit(Result.failure(t))
}
}
}
}

override suspend fun checkNicknameDB(nickname: String, isExist: String): Flow<Result<String>> {
override fun checkNicknameDB(nickname: String, isExist: String): Flow<Result<String>> {
return flow {
userRemoteData.postCheckNickname(CheckNicknameReq(nickname, isExist)).map {
it.onSuccess { res ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ interface UserRepository {
suspend fun getCurrentUser(): Result<UserPreference>
suspend fun deleteUserInformation(): UserPreference
fun signIn(accountName: String, password: String): Flow<Result<SignInInfo>>
fun signUp(loginId: String, password: String, phoneNumber: String, nickname: String): Flow<Result<SignUpInfo>>
fun signUp(
loginId: String,
password: String,
phoneNumber: String,
nickname: String
): Flow<Result<SignUpInfo>>

fun refreshToken(): Flow<Result<String>>
suspend fun checkPhoneNumDB(phoneNumber: String, isExist: String): Flow<Result<String>>
suspend fun checkUserIdDB(userId: String, isExist: String): Flow<Result<String>>
suspend fun checkNicknameDB(nickname: String, isExist: String): Flow<Result<String>>
fun checkPhoneNumDB(phoneNumber: String, isExist: String): Flow<Result<String>>
fun checkUserIdDB(userId: String, isExist: String): Flow<Result<String>>
fun checkNicknameDB(nickname: String, isExist: String): Flow<Result<String>>
suspend fun saveSignInInfo(signInInfo: SignInInfo)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bmsk.domain.usecase

import android.util.Log
import kotlinx.coroutines.flow.Flow
import org.bmsk.domain.model.SignInInfo
import org.bmsk.domain.model.SignUpInfo
Expand All @@ -18,10 +19,36 @@ class UserUseCase @Inject constructor(

fun signIn(accountName: String, password: String) = repository.signIn(accountName, password)

fun signUp(loginId: String, password: String, phoneNumber: String, nickname: String): Flow<Result<SignUpInfo>> {
fun signUp(
loginId: String,
password: String,
phoneNumber: String,
nickname: String
): Flow<Result<SignUpInfo>> {
return repository.signUp(loginId, password, phoneNumber, nickname)
}

fun checkPhoneDup(phoneNumber: String, isExist: String): Flow<Result<String>> {
return repository.checkPhoneNumDB(phoneNumber, isExist)
}

fun checkIdDup(loginId: String, isExist: String): Flow<Result<String>> {
Log.d("UserUserCase", "usecase")
return repository.checkUserIdDB(loginId, isExist)
}

fun checkNicknameDup(nickname: String, isExist: String): Flow<Result<String>> {
return repository.checkNicknameDB(nickname, isExist)
}

fun receiveCode(phoneNumber: String): Flow<Result<String>>? {
return null
}

fun sendCode(phoneNumber: String, code: Int): Flow<Result<String>>? {
return null
}

suspend fun saveUserSignInformation(signInInfo: SignInInfo) {
repository.saveSignInInfo(signInInfo)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cazait.network.datasource

import android.accounts.NetworkErrorException
import android.util.Log
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.bmsk.domain.exception.EmptyDataException
Expand All @@ -26,9 +27,10 @@ fun <T> processCall(call: suspend () -> Response<CazaitResponse<T>>): Flow<Resul
fun <T> normalProcessCall(call: suspend () -> Response<T>): Flow<Result<T>> {
return flow {
val response = call()
Log.d("ProcessCall", response.toString())
if (response.isSuccessful) {
response.body()?.let {
emit(Result.success(it))
response.body()?.let { res ->
emit(Result.success(res))
}
} else {
emit(Result.failure(NetworkErrorException()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cazait.network.datasource

import android.util.Log
import kotlinx.coroutines.flow.Flow
import org.bmsk.domain.model.Role
import org.cazait.network.api.AuthService
Expand Down Expand Up @@ -40,7 +41,11 @@ class UserRemoteData @Inject constructor(
}

override suspend fun postCheckUserId(body: CheckUserIdReq): Flow<Result<CheckRes>> {
return normalProcessCall { userService.postUserIdDB(body) }
Log.d("UserRemoteData IdDup", body.toString())
return normalProcessCall {
Log.d("UserRemoteData IdDup", userService.postUserIdDB(body).toString())
userService.postUserIdDB(body)
}
}

override suspend fun postCheckNickname(body: CheckNicknameReq): Flow<Result<CheckRes>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import org.cazait.presentation.R
import org.cazait.presentation.databinding.FragmentSignUpBinding
import org.cazait.presentation.ui.util.toGone
import org.cazait.presentation.ui.util.toVisible

@AndroidEntryPoint
class SignUpFragment : Fragment() {
Expand Down Expand Up @@ -42,6 +45,7 @@ class SignUpFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.layoutVerificationCodeInput.toGone()
observeViewModel()
}

Expand All @@ -55,6 +59,23 @@ class SignUpFragment : Fragment() {
}
}
}
launch {
viewModel.checkPhoneDupStateFlow.collect {
binding.layoutVerificationCodeInput.toVisible()
viewModel.showToastMessage(it)
viewModel.receiveCode()
}
}
launch {
viewModel.checkIdDupStateFlow.collect {
viewModel.showToastMessage(it)
}
}
launch {
viewModel.checkNicknameDupStateFlow.collect {
viewModel.showToastMessage(it)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class SignUpViewModel @Inject constructor(
private val _signUpInfoStateFlow = MutableStateFlow<SignUpInfo?>(null)
val signUpInfoStateFlow = _signUpInfoStateFlow.asStateFlow()

private val _checkPhoneDupStateFlow = MutableStateFlow<String?>(null)
val checkPhoneDupStateFlow = _checkPhoneDupStateFlow.asStateFlow()

private val _checkIdDupStateFlow = MutableStateFlow<String?>(null)
val checkIdDupStateFlow = _checkIdDupStateFlow.asStateFlow()

private val _checkNicknameDupStateFlow = MutableStateFlow<String?>(null)
val checkNicknameDupStateFlow = _checkNicknameDupStateFlow.asStateFlow()

private val _guideMessage = MutableStateFlow("")
val guideMessage = _guideMessage.asStateFlow()

Expand All @@ -45,12 +54,38 @@ class SignUpViewModel @Inject constructor(
}
}

fun checkIdDup() {
fun checkPhoneDup() {
viewModelScope.launch {
userUseCase.checkPhoneDup(phoneNumberText.value, "false").collect { result ->
Log.d("SignUpViewModel Phone Dup", result.toString())
result.onSuccess {
_checkPhoneDupStateFlow.value = it
}
}
}
}

fun checkIdDup() {
Log.d("SignUpViewModel Clicked?", "adsf")
viewModelScope.launch {
userUseCase.checkIdDup(idText.value, "false").collect { result ->
Log.d("SignUpViewModel Id Dup", result.toString())
result.onSuccess {
_checkIdDupStateFlow.value = it
}
}
}
}

fun checkNicknameDup() {

viewModelScope.launch {
userUseCase.checkNicknameDup(nicknameText.value, "false").collect { result ->
Log.d("SignUpViewModel Nickname Dup", result.toString())
result.onSuccess {
_checkNicknameDupStateFlow.value = it
}
}
}
}

fun receiveCode() {
Expand All @@ -60,4 +95,9 @@ class SignUpViewModel @Inject constructor(
fun sendCode() {

}

fun showToastMessage(errorMessage: String?) {
if (errorMessage == null) return
_guideMessage.value = errorMessage
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.cazait.presentation.ui.util

import android.view.View

fun View.toVisible() {
this.visibility = View.VISIBLE
}

fun View.toGone() {
this.visibility = View.GONE
}
3 changes: 2 additions & 1 deletion core/presentation/src/main/res/layout/fragment_sign_up.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rectangle_black_r20"
android:onClick="@{() -> viewModel.receiveCode()}"
android:onClick="@{() -> viewModel.checkPhoneDup()}"
android:paddingHorizontal="16dp"
android:text="@string/receive_code"
android:textColor="@color/white"
Expand All @@ -177,6 +177,7 @@
android:id="@+id/layout_verificationCode_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/phoneNumberTextInputLayout">
Expand Down

0 comments on commit 656f1f0

Please sign in to comment.