From 0434efb36c04a3b1f1acda91a9c6b9a21c06a036 Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Wed, 30 Nov 2022 22:50:38 +0900 Subject: [PATCH] =?UTF-8?q?[Chore]=20#12=20-=20FormValid=20=ED=8C=90?= =?UTF-8?q?=EB=8B=A8=20=EB=A1=9C=EC=A7=81=20=EC=9C=84=EC=B9=98=EB=A5=BC=20?= =?UTF-8?q?UseCase=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/UseCase/SignUpUseCase.swift | 26 ++++++++++++++++--- .../ViewModel/SignUpViewModel.swift | 15 +++-------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/SignUpUseCase.swift b/SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/SignUpUseCase.swift index 5adbf7db..7adb6c51 100644 --- a/SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/SignUpUseCase.swift +++ b/SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/SignUpUseCase.swift @@ -9,6 +9,8 @@ import Foundation import Combine +import Core + public protocol SignUpUseCase { func checkNickname(nickname: String) func checkEmail(email: String) @@ -19,20 +21,23 @@ public protocol SignUpUseCase { var isEmailFormValid: CurrentValueSubject { get set } var isPasswordFormValid: CurrentValueSubject { get set } var isAccordPassword: CurrentValueSubject { get set } + var isValidForm: CurrentValueSubject { get set } } public class DefaultSignUpUseCase { private let repository: SignUpRepositoryInterface - private var cancelBag = Set() + private var cancelBag = CancelBag() public var isNicknameValid = CurrentValueSubject(false) public var isEmailFormValid = CurrentValueSubject(false) public var isPasswordFormValid = CurrentValueSubject(false) public var isAccordPassword = CurrentValueSubject(false) - + public var isValidForm = CurrentValueSubject(false) + public init(repository: SignUpRepositoryInterface) { self.repository = repository + self.bindFormValid() } } @@ -62,6 +67,21 @@ extension DefaultSignUpUseCase: SignUpUseCase { // MARK: - Methods extension DefaultSignUpUseCase { + func bindFormValid() { + isNicknameValid.combineLatest( + isEmailFormValid, + isPasswordFormValid, + isAccordPassword) + .map { (isNicknameValid, isEmailValid, isPasswordValid, isAccordPassword) in + (isNicknameValid && isEmailValid && isPasswordValid && isAccordPassword) + } + .sink { event in + print("SignUpUseCase - completion: \(event)") + } receiveValue: { isValid in + self.isValidForm.send(isValid) + }.store(in: cancelBag) + } + func checkNicknameForm(nickname: String) -> Bool { isNicknameValid.send(true) return true @@ -76,7 +96,7 @@ extension DefaultSignUpUseCase { } func checkPasswordForm(password: String) { - let passwordRegEx = "^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[!@#$%^&*()_+=-]).{8,16}" // 8자리 ~ 16자리 영어+숫자+특수문자 + let passwordRegEx = "^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[!@#$%^&*()_+=-]).{8,15}" // 8자리 ~ 15자리 영어+숫자+특수문자 let passwordTest = NSPredicate(format: "SELF MATCHES %@", passwordRegEx) let isValid = passwordTest.evaluate(with: password) isPasswordFormValid.send(isValid) diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/SignUpScene/ViewModel/SignUpViewModel.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/SignUpScene/ViewModel/SignUpViewModel.swift index 012e63d3..dd0f2d97 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/SignUpScene/ViewModel/SignUpViewModel.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/SignUpScene/ViewModel/SignUpViewModel.swift @@ -101,18 +101,11 @@ extension SignUpViewModel { output.passwordAlert.send("") } }.store(in: cancelBag) - - useCase.isNicknameValid.combineLatest( - useCase.isEmailFormValid, - useCase.isPasswordFormValid, - useCase.isAccordPassword) - .map { (isNicknameValid, isEmailValid, isPasswordValid, isAccordPassword) in - (isNicknameValid && isEmailValid && isPasswordValid && isAccordPassword) - } - .sink { event in + + useCase.isValidForm.sink { event in print("SignUpViewModel - completion: \(event)") - } receiveValue: { isValid in - output.isValidForm.send(isValid) + } receiveValue: { isValidForm in + output.isValidForm.send(isValidForm) }.store(in: cancelBag) } }