Skip to content

Commit

Permalink
Feat: 닉네임 중복 네트워크 로직 선언
Browse files Browse the repository at this point in the history
  • Loading branch information
GeonH0 committed Jan 7, 2025
1 parent 318a242 commit 00cb691
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// CheckNicknameService.swift
// HomeCafeRecipes
//
// Created by 김건호 on 1/6/25.
//

import Foundation

import RxSwift

protocol CheckNicknameService {
func checkNickname(nickname: String) -> Single<Bool>
}

final class CheckNicknameServiceImpl: CheckNicknameService {
private let network : BaseNetworkService

init(network: BaseNetworkService) {
self.network = network
}

private func makeURL(ednpoint: String) -> URL {
return APIConfig().baseURL.appendingPathComponent(ednpoint)
}

func checkNickname(nickname: String) -> Single<Bool> {
var components = URLComponents(url: makeURL(ednpoint: "verification/checkNickname"), resolvingAgainstBaseURL: false)
components?.queryItems = [
URLQueryItem(name: "nickname", value: nickname),
]

guard let urlWithQuery = components?.url else {
return Single.error(NSError(domain: "Invalid URL", code: -1, userInfo: nil))
}

return network.getRequest(
url: urlWithQuery,
responseType: NetworkResponseDTO<CheckNicknameDTO>.self
)
.map { $0.data.isDuplicate }
.do(onSuccess: { isDuplicate in
print("Is Duplicate: \(isDuplicate)")
print(nickname)
}, onError: { error in
print("Error occurred: \(error.localizedDescription)")
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// CheckNicknameDTO.swift
// HomeCafeRecipes
//
// Created by 김건호 on 1/6/25.
//

import Foundation

struct CheckNicknameDTO: Decodable {
let isDuplicate: Bool
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// CheckNicknameRepository.swift
// HomeCafeRecipes
//
// Created by 김건호 on 1/6/25.
//

import RxSwift

protocol CheckNicknameRepository {
func checkNicknameAvailability(nickname: String) -> Single<Bool>
}

// Repository Implementation
final class CheckNicknameRepositoryImpl: CheckNicknameRepository {
private let service: CheckNicknameService

init(service: CheckNicknameService) {
self.service = service
}

func checkNicknameAvailability(nickname: String) -> Single<Bool> {
return service.checkNickname(nickname: nickname)
}
}

0 comments on commit 00cb691

Please sign in to comment.