diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/Network/EmailVerificationCodeService.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/EmailVerificationCodeService.swift new file mode 100644 index 0000000..fe97045 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/EmailVerificationCodeService.swift @@ -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 +} + +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 { + 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.self + ) + .map { $0.data } + } +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/EmailVerificationCodeRepository.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/EmailVerificationCodeRepository.swift new file mode 100644 index 0000000..dda9812 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/EmailVerificationCodeRepository.swift @@ -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 +} + +final class ValidateEmailCodeRepositoryImpl: ValidateEmailCodeRepository { + private let service: EmailVerificationCodeService + init(service: EmailVerificationCodeService) { + self.service = service + } + func checkVerificationCode(email: String, code: String) -> Single { + return service.validateEmailCode(email: email, code: code) + } +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/ValidateEmailCodeUseCase.swift b/HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/ValidateEmailCodeUseCase.swift new file mode 100644 index 0000000..93fece4 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/ValidateEmailCodeUseCase.swift @@ -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 +} + +final class ValidateEmailCodeUseCaseImpl: ValidateEmailCodeUseCase { + private let repository: ValidateEmailCodeRepository + + init(repository: ValidateEmailCodeRepository) { + self.repository = repository + } + + func excute(email:String,code: String) -> Single { + return repository.checkVerificationCode(email:email, code: code) + } +}