Skip to content

Commit

Permalink
[REFACTOR] #141 : validate -> check로 네이밍 변경 및 통일
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Mar 3, 2024
1 parent a955f68 commit 9c542c0
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface AuthRepository {

suspend fun isUserSignIn(): Result<Boolean>

suspend fun validateMemberCode(code: String): Result<Boolean>
suspend fun checkMemberCode(code: String): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class AuthRepositoryImpl @Inject constructor(

override suspend fun isUserSignIn(): Result<Boolean> = authDataSource.isUserSignIn()

override suspend fun validateMemberCode(code: String): Result<Boolean> =
authDataSource.validateMemberCode(code)
override suspend fun checkMemberCode(code: String): Result<Boolean> =
authDataSource.checkMemberCode(code)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface ManagementRepository {

suspend fun postManager(userId: String): Result<Unit>

suspend fun getManagementCode(code: String): Result<Boolean>
suspend fun checkManagementCode(code: String): Result<Boolean>

suspend fun deleteManager(userId: String): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ManagementRepositoryImpl @Inject constructor(
override suspend fun postManager(userId: String): Result<Unit> =
managementDataSource.postManager(userId)

override suspend fun getManagementCode(code: String): Result<Boolean> =
managementDataSource.getManagementCode(code)
override suspend fun checkManagementCode(code: String): Result<Boolean> =
managementDataSource.checkManagementCode(code)

override suspend fun deleteManager(userId: String): Result<Unit> =
managementDataSource.deleteManager(userId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.wap.wapp.core.domain.usecase.auth

import com.wap.wapp.core.data.repository.auth.AuthRepository
import com.wap.wapp.core.domain.model.CodeValidation
import javax.inject.Inject

class ValidateWapMemberCodeUseCase @Inject constructor(
private val signUpRepository: SignUpRepository,
class CheckMemberCodeUseCase @Inject constructor(
private val authRepository: AuthRepository,
) {
suspend operator fun invoke(code: String): Result<CodeValidation> = runCatching {
signUpRepository.validationWapCode(code).fold(
authRepository.checkMemberCode(code).fold(
onSuccess = { isValid ->
if (isValid) {
return@fold CodeValidation.VALID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ValidateManagementCodeUseCase @Inject constructor(
class CheckManagementCodeUseCase @Inject constructor(
private val managementRepository: ManagementRepository,
private val userRepository: UserRepository,
) {
suspend operator fun invoke(code: String): Result<CodeValidation> = runCatching {
managementRepository.getManagementCode(code)
managementRepository.checkManagementCode(code)
.onSuccess { isValid ->
if (isValid.not()) { // 코드가 틀렸을 경우
return@runCatching CodeValidation.INVALID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface AuthDataSource {

suspend fun isUserSignIn(): Result<Boolean>

suspend fun validateMemberCode(code: String): Result<Boolean>
suspend fun checkMemberCode(code: String): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AuthDataSourceImpl @Inject constructor(
}
}

override suspend fun validateMemberCode(code: String): Result<Boolean> = runCatching {
override suspend fun checkMemberCode(code: String): Result<Boolean> = runCatching {
val result = firebaseFirestore.collection(CODES_COLLECTION)
.whereEqualTo("user", code)
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface ManagementDataSource {

suspend fun postManager(userId: String): Result<Unit>

suspend fun getManagementCode(code: String): Result<Boolean>
suspend fun checkManagementCode(code: String): Result<Boolean>

suspend fun deleteManager(userId: String): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ManagementDataSourceImpl @Inject constructor(
.await()
}

override suspend fun getManagementCode(code: String): Result<Boolean> = runCatching {
override suspend fun checkManagementCode(code: String): Result<Boolean> = runCatching {
val result = firebaseFirestore.collection(CODES_COLLECTION)
.whereEqualTo("management", code)
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.wap.wapp.feature.auth.signup
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wap.wapp.core.domain.model.CodeValidation
import com.wap.wapp.core.domain.usecase.auth.ValidateWapMemberCodeUseCase
import com.wap.wapp.core.domain.usecase.auth.CheckMemberCodeUseCase
import com.wap.wapp.core.domain.usecase.user.PostUserProfileUseCase
import com.wap.wapp.feature.auth.R
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -19,7 +19,7 @@ import javax.inject.Inject
@HiltViewModel
class SignUpViewModel @Inject constructor(
private val postUserProfileUseCase: PostUserProfileUseCase,
private val validateWapMemberCodeUseCase: ValidateWapMemberCodeUseCase,
private val checkMemberCodeUseCase: CheckMemberCodeUseCase,
) : ViewModel() {
private val _signUpEventFlow = MutableSharedFlow<SignUpEvent>()
val signUpEventFlow: SharedFlow<SignUpEvent> = _signUpEventFlow.asSharedFlow()
Expand Down Expand Up @@ -58,7 +58,7 @@ class SignUpViewModel @Inject constructor(
}

fun validateMemberCode() = viewModelScope.launch {
validateWapMemberCodeUseCase(_memberCode.value).onSuccess {
checkMemberCodeUseCase(_memberCode.value).onSuccess {
when (it) {
CodeValidation.VALID ->
_signUpEventFlow.emit(SignUpEvent.ValidateMemberCodeSuccess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.wap.wapp.feature.management.validation
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wap.wapp.core.domain.model.CodeValidation
import com.wap.wapp.core.domain.usecase.management.ValidateManagementCodeUseCase
import com.wap.wapp.core.domain.usecase.management.CheckManagementCodeUseCase
import com.wap.wapp.feature.management.R
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -13,7 +13,7 @@ import javax.inject.Inject

@HiltViewModel
class ManagementValidationViewModel @Inject constructor(
private val validateManagementCodeUseCase: ValidateManagementCodeUseCase,
private val checkManagementCodeUseCase: CheckManagementCodeUseCase,
) : ViewModel() {
private val _managementCodeUiState: MutableStateFlow<ManagementCodeUiState> =
MutableStateFlow(ManagementCodeUiState.Init)
Expand All @@ -32,7 +32,7 @@ class ManagementValidationViewModel @Inject constructor(

fun validateManagementCode() {
viewModelScope.launch {
validateManagementCodeUseCase(_managementCode.value)
checkManagementCodeUseCase(_managementCode.value)
.onSuccess {
when (it) {
CodeValidation.VALID -> {
Expand Down

0 comments on commit 9c542c0

Please sign in to comment.