Skip to content

Commit

Permalink
[Fix] 비밀번호 수정 서버 에러 해결 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeseSR committed May 10, 2022
1 parent cbae5b8 commit 07ed929
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
28 changes: 5 additions & 23 deletions Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ public class PasswordAPI {

public init() { }

func putNewPassword(completion: @escaping (NetworkResult<Any>) -> Void, email: String, password: String) {
courseProvider.request(.putChangedPassword(email: email, password: password)) { (result) in
func postNewPassword(completion: @escaping (NetworkResult<Any>) -> Void, email: String, password: String) {
courseProvider.request(.postChangedPassword(email: email, password: password)) { (result) in
print(result)
switch result {
case .success(let response):
print("response 제대로 오는지 확인: ", response)
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeChangePasswordStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data)
completion(networkResult)

case .failure(let err):
Expand Down Expand Up @@ -100,24 +102,4 @@ public class PasswordAPI {
return .networkFail
}
}

// private func judgeGetEmailCodeStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {
//
// let decoder = JSONDecoder()
// guard let decodedData = try? decoder.decode(GenericResponse<EmailCheckData>.self, from: data) else {
// return .pathErr
// }
//
// switch statusCode {
// case 200:
// return .success(decodedData.data)
// case 400..<500:
// return .requestErr(decodedData.message)
// case 500:
// return .serverErr
// default:
// return .networkFail
// }
// }
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import Moya

enum PasswordService {
case putChangedPassword(email: String, password: String)
case postChangedPassword(email: String, password: String)
case postEmailCode(email: String)
case checkCode(email: String, authNum: String)

Expand All @@ -22,7 +22,7 @@ extension PasswordService: TargetType {

var path: String {
switch self {
case .putChangedPassword(_, _):
case .postChangedPassword(_, _):
return Const.URL.passwordURL
case .postEmailCode(let email):
return Const.URL.findPasswordURL + "/\(email)"
Expand All @@ -33,8 +33,8 @@ extension PasswordService: TargetType {

var method: Moya.Method {
switch self {
case .putChangedPassword(_, _):
return .put
case .postChangedPassword(_, _):
return .post
case .postEmailCode(_):
return .post
case .checkCode(_, _):
Expand All @@ -48,10 +48,11 @@ extension PasswordService: TargetType {

var task: Task {
switch self {
case .putChangedPassword(let email, let password):
case .postChangedPassword(let email, let password):
// body가 있는 request - JSONEncoding.default
return .requestParameters(parameters: [
"email": email,
"username": "",
"password": password
], encoding: JSONEncoding.default)
case .postEmailCode(_):
Expand Down

0 comments on commit 07ed929

Please sign in to comment.