Skip to content

Commit

Permalink
[chore] #7 validate result
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook123 committed May 10, 2024
1 parent c9cc50a commit 74e303b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.sopt.domain.usecase

import org.sopt.model.ValidateResult
import org.sopt.model.getResult
import javax.inject.Inject

class ValidatePasswordUseCase @Inject constructor() {
operator fun invoke(password: String): ValidateResult {
if (password.isBlank()) return ValidateResult.EmptyError
return getResult(passwordPattern.matches(password))
return ValidateResult.getResult(passwordPattern.matches(password))
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.sopt.domain.usecase

import org.sopt.model.ValidateResult
import org.sopt.model.getResult
import javax.inject.Inject

class ValidatePhoneNumberUseCase @Inject constructor() {
operator fun invoke(phone: String): ValidateResult {
if (phone.isBlank()) return ValidateResult.EmptyError
return getResult(phoneNumberPattern.matches(phone))
return ValidateResult.getResult(phoneNumberPattern.matches(phone))
}

companion object {
Expand Down
6 changes: 4 additions & 2 deletions core/model/src/main/java/org/sopt/model/ValidateResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sealed class ValidateResult {
data object EmptyError : ValidateResult()
data object Error : ValidateResult()
data object Success : ValidateResult()
}

fun getResult(isValid: Boolean) = if (isValid) ValidateResult.Success else ValidateResult.Error
companion object{
fun getResult(isValid: Boolean) = if (isValid) Success else Error
}
}

0 comments on commit 74e303b

Please sign in to comment.