-
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
86 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
HomeCafeRecipes/HomeCafeRecipes/Data/Network/CheckNicknameService.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,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)") | ||
}) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/CheckNicknameDTO.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,12 @@ | ||
// | ||
// CheckNicknameDTO.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 1/6/25. | ||
// | ||
|
||
import Foundation | ||
|
||
struct CheckNicknameDTO: Decodable { | ||
let isDuplicate: Bool | ||
} |
25 changes: 25 additions & 0 deletions
25
HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/CheckNicknameRepository.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,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) | ||
} | ||
} |