-
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
4 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/EmptyResponse.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,10 @@ | ||
// | ||
// EmptyResponse.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 9/11/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct EmptyResponse: Decodable {} |
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
63 changes: 63 additions & 0 deletions
63
HomeCafeRecipes/HomeCafeRecipes/Data/Network/SignUpService.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,63 @@ | ||
// | ||
// SignUpService.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 9/11/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import RxSwift | ||
|
||
protocol SignUpService { | ||
func signUp( | ||
userNickName: String, | ||
userID: String, | ||
password: String | ||
) -> Single<Void> | ||
} | ||
|
||
final class SignUpServiceImpl: SignUpService { | ||
private let networkService: NetworkService | ||
|
||
init(networkService: NetworkService) { | ||
self.networkService = networkService | ||
} | ||
|
||
private func makeURL(endpoint: String) -> URL { | ||
return APIConfig().baseURL.appendingPathComponent(endpoint) | ||
} | ||
|
||
func signUp( | ||
userNickName: String, | ||
userID: String, | ||
password: String | ||
) -> Single<Void> { | ||
let url = makeURL(endpoint: "auth/register") | ||
|
||
let parameters: [String: Any] = [ | ||
"email": userID, | ||
"password": password, | ||
"nickname": userNickName | ||
] | ||
|
||
return networkService.postJsonRequest( | ||
url: url, | ||
parameters: parameters, | ||
responseType: NetworkResponseDTO<EmptyResponse>.self | ||
) | ||
.flatMap { response in | ||
if response.statusCode == 200 { | ||
// 성공 시 data가 null이더라도 성공 처리 | ||
return .just(()) | ||
} else { | ||
// statusCode가 200이 아니면 에러 처리 | ||
return .error(NSError(domain: "SignUpError", code: response.statusCode, userInfo: [NSLocalizedDescriptionKey: response.message])) | ||
} | ||
} | ||
.catch { error in | ||
// 네트워크 또는 서버에서 에러가 발생했을 경우 처리 | ||
return .error(error) | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/SignUpRepository.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,31 @@ | ||
// | ||
// SignUpRepository.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 9/10/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import RxSwift | ||
|
||
protocol SignUpRepository { | ||
func signUp(userNickName: String, userID: String, password: String) -> Single<Void> | ||
} | ||
|
||
final class SignUpRepositoryImpl: SignUpRepository { | ||
|
||
private let SignUpService: SignUpService | ||
|
||
init(SignUpService: SignUpService) { | ||
self.SignUpService = SignUpService | ||
} | ||
|
||
func signUp(userNickName: String, userID: String, password: String) -> Single<Void> { | ||
return SignUpService.signUp( | ||
userNickName: userNickName, | ||
userID: userID, | ||
password: password | ||
) | ||
} | ||
} |