Skip to content

Commit

Permalink
fix: api 수정 (TeamNADA#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyun99999 committed Mar 30, 2023
1 parent 0ada957 commit eb1d6fd
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions NADA-iOS-forRelease/Sources/NetworkService/User/UserAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public class UserAPI {
}
}

func userSocialSignUp(request: String, completion: @escaping (NetworkResult<Any>) -> Void) {
userProvider.request(.userSocialSignUp(userID: request)) { (result) in
func userSocialSignUp(socialID: String, socialType: String, completion: @escaping (NetworkResult<Any>) -> Void) {
userProvider.request(.userSocialSignUp(socialID: socialID, socialType: socialType)) { result in
switch result {
case .success(let response):
let statusCode = response.statusCode
let data = response.data
let networkResult = self.judgeUserTokenFetchStatus(by: statusCode, data)
let networkResult = self.judgeUserSocialSignUpStatus(by: statusCode, data)
completion(networkResult)

case .failure(let err):
Expand Down Expand Up @@ -78,6 +78,25 @@ public class UserAPI {
}
}

private func judgeUserSocialSignUpStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<AccessToken>.self, from: data)
else {
return .pathErr
}

switch statusCode {
case 200:
return .success(decodedData.data ?? "None-Data")
case 400..<500:
return .requestErr(decodedData.error?.message ?? "error message")
case 500:
return .serverErr
default:
return .networkFail
}
}

private func judgeUserTokenFetchStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {

let decoder = JSONDecoder()
Expand Down

0 comments on commit eb1d6fd

Please sign in to comment.