-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] #12 - 회원가입 뷰 구현
- Loading branch information
Showing
14 changed files
with
650 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
SOPT-Stamp-iOS/Projects/Data/Sources/Repository/SignUpRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// SignUpRepository.swift | ||
// Data | ||
// | ||
// Created by sejin on 2022/11/28. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Combine | ||
|
||
import Domain | ||
import Network | ||
|
||
public class SignUpRepository { | ||
|
||
private let networkService: AuthService | ||
private let cancelBag = Set<AnyCancellable>() | ||
|
||
public init(service: AuthService) { | ||
self.networkService = service | ||
} | ||
} | ||
|
||
extension SignUpRepository: SignUpRepositoryInterface { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
SOPT-Stamp-iOS/Projects/Data/Sources/Transform/SignUpTransform.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// SignUpTransform.swift | ||
// Data | ||
// | ||
// Created by sejin on 2022/11/28. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Domain | ||
import Network | ||
|
||
extension SignUpEntity { | ||
|
||
public func toDomain() -> SignUpModel { | ||
return SignUpModel.init() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
SOPT-Stamp-iOS/Projects/Domain/Sources/Model/SignUpModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// SignUpModel.swift | ||
// Domain | ||
// | ||
// Created by sejin on 2022/11/28. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct SignUpModel { | ||
|
||
public init() { | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
SOPT-Stamp-iOS/Projects/Domain/Sources/RepositoryInterface/SignUpRepositoryInterface.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// SignUpRepositoryInterface.swift | ||
// Domain | ||
// | ||
// Created by sejin on 2022/11/28. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Combine | ||
|
||
public protocol SignUpRepositoryInterface { | ||
|
||
} |
109 changes: 109 additions & 0 deletions
109
SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/SignUpUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// SignUpUseCase.swift | ||
// Domain | ||
// | ||
// Created by sejin on 2022/11/28. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
import Core | ||
|
||
public protocol SignUpUseCase { | ||
func checkNickname(nickname: String) | ||
func checkEmail(email: String) | ||
func checkPassword(password: String) | ||
func checkAccordPassword(firstPassword: String, secondPassword: String) | ||
|
||
var isNicknameValid: CurrentValueSubject<Bool, Error> { get set } | ||
var isEmailFormValid: CurrentValueSubject<Bool, Error> { get set } | ||
var isPasswordFormValid: CurrentValueSubject<Bool, Error> { get set } | ||
var isAccordPassword: CurrentValueSubject<Bool, Error> { get set } | ||
var isValidForm: CurrentValueSubject<Bool, Error> { get set } | ||
} | ||
|
||
public class DefaultSignUpUseCase { | ||
|
||
private let repository: SignUpRepositoryInterface | ||
private var cancelBag = CancelBag() | ||
|
||
public var isNicknameValid = CurrentValueSubject<Bool, Error>(false) | ||
public var isEmailFormValid = CurrentValueSubject<Bool, Error>(false) | ||
public var isPasswordFormValid = CurrentValueSubject<Bool, Error>(false) | ||
public var isAccordPassword = CurrentValueSubject<Bool, Error>(false) | ||
public var isValidForm = CurrentValueSubject<Bool, Error>(false) | ||
|
||
public init(repository: SignUpRepositoryInterface) { | ||
self.repository = repository | ||
self.bindFormValid() | ||
} | ||
} | ||
|
||
extension DefaultSignUpUseCase: SignUpUseCase { | ||
public func checkNickname(nickname: String) { | ||
// 닉네임 글자 수 정해지면 로직 추가 | ||
let isValid = checkNicknameForm(nickname: nickname) | ||
guard isValid else { return } | ||
// 서버 통신 | ||
} | ||
|
||
public func checkEmail(email: String) { | ||
let isValid = checkEmailForm(email: email) | ||
guard isValid else { return } | ||
// 서버 통신 | ||
} | ||
|
||
public func checkPassword(password: String) { | ||
checkPasswordForm(password: password) | ||
} | ||
|
||
public func checkAccordPassword(firstPassword: String, secondPassword: String) { | ||
checkAccordPasswordForm(firstPassword: firstPassword, secondPassword: secondPassword) | ||
} | ||
} | ||
|
||
// 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 | ||
} | ||
|
||
func checkEmailForm(email: String) -> Bool { | ||
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | ||
let emailTest = NSPredicate(format: "SELF MATCHES %@", emailRegEx) | ||
let isValid = emailTest.evaluate(with: email) | ||
isEmailFormValid.send(isValid) | ||
return isValid | ||
} | ||
|
||
func checkPasswordForm(password: String) { | ||
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) | ||
} | ||
|
||
func checkAccordPasswordForm(firstPassword: String, secondPassword: String) { | ||
let isValid = (firstPassword == secondPassword) | ||
isAccordPassword.send(isValid) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.