-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
HomeCafeRecipes/HomeCafeRecipes/Data/Network/EmailVerificationCodeService.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,45 @@ | ||
// | ||
// EmailVerificationCodeService.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 12/24/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import RxSwift | ||
|
||
protocol EmailVerificationCodeService { | ||
func validateEmailCode(email:String, code:String) -> Single<Bool> | ||
} | ||
|
||
final class EmailVerificationCodeServiceImpl: EmailVerificationCodeService { | ||
private let network : BaseNetworkService | ||
|
||
init(network: BaseNetworkService) { | ||
self.network = network | ||
} | ||
|
||
private func makeURL(ednpoint: String) -> URL { | ||
return APIConfig().baseURL.appendingPathComponent(ednpoint) | ||
} | ||
|
||
func validateEmailCode(email: String, code: String) -> Single<Bool> { | ||
var components = URLComponents(url: makeURL(ednpoint: "verification/verifyCode"), resolvingAgainstBaseURL: false) | ||
components?.queryItems = [ | ||
URLQueryItem(name: "email", value: email), | ||
URLQueryItem(name: "code", value: code) | ||
] | ||
|
||
guard let urlWithQuery = components?.url else { | ||
return Single.error(NSError(domain: "Invalid URL", code: -1, userInfo: nil)) | ||
} | ||
|
||
return network.postJsonRequest( | ||
url: urlWithQuery, | ||
parameters: [:], | ||
responseType: NetworkResponseDTO<Bool>.self | ||
) | ||
.map { $0.data } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/EmailVerificationCodeRepository.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,24 @@ | ||
// | ||
// ValidateEmailCodeRepository.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 12/24/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import RxSwift | ||
|
||
protocol ValidateEmailCodeRepository { | ||
func checkVerificationCode(email:String, code: String) -> Single<Bool> | ||
} | ||
|
||
final class ValidateEmailCodeRepositoryImpl: ValidateEmailCodeRepository { | ||
private let service: EmailVerificationCodeService | ||
init(service: EmailVerificationCodeService) { | ||
self.service = service | ||
} | ||
func checkVerificationCode(email: String, code: String) -> Single<Bool> { | ||
return service.validateEmailCode(email: email, code: code) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/ValidateEmailCodeUseCase.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 @@ | ||
// | ||
// ValidateEmailCodeUseCase.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 12/24/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import RxSwift | ||
|
||
protocol ValidateEmailCodeUseCase { | ||
func excute(email:String, code: String) -> Single<Bool> | ||
} | ||
|
||
final class ValidateEmailCodeUseCaseImpl: ValidateEmailCodeUseCase { | ||
private let repository: ValidateEmailCodeRepository | ||
|
||
init(repository: ValidateEmailCodeRepository) { | ||
self.repository = repository | ||
} | ||
|
||
func excute(email:String,code: String) -> Single<Bool> { | ||
return repository.checkVerificationCode(email:email, code: code) | ||
} | ||
} |