Skip to content

Commit

Permalink
Feat: 이메일 인증하는 로직 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
GeonH0 committed Jan 1, 2025
1 parent 5141b16 commit 10b109d
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
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 }
}
}
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)
}
}
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)
}
}

0 comments on commit 10b109d

Please sign in to comment.