Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop'
Browse files Browse the repository at this point in the history
Conflicts:
	KeKi/Scenes/Login/UserProfileSetting/BuyerProfileSetViewController.swift
	KeKi/Scenes/Login/UserProfileSetting/SellerProfileSetViewController.swift
  • Loading branch information
chayoosang committed Mar 9, 2023
2 parents 7c7326e + 3ad4240 commit 35faf4b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 44 deletions.
Empty file added FETCH_HEAD
Empty file.
2 changes: 1 addition & 1 deletion KeKi/Data/Model/AuthModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct AuthResponse: Codable {
var isSuccess: Bool
var code: Int
var message: String
var result: Result
var result: Result?

struct Result: Codable {
var accessToken: String
Expand Down
45 changes: 24 additions & 21 deletions KeKi/Data/Network/APIManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,31 @@ extension APIManeger {
dataType: T.Type,
parameter: T,
completionHandler: @escaping (AuthResponse) -> Void) {

// let accessToken = UserDefaults.standard.value(forKey: "accessToken") as! String
// let header = APIManeger.shared.getHeaderByToken(accessToken: accessToken)

guard let url = URL(string: DEV_BASE_URL + urlEndpointString) else { return }
if let _ = UserDefaults.standard.value(forKey: "accessToken") {

let accessToken = UserDefaults.standard.value(forKey: "accessToken") as! String
let header = APIManeger.shared.getHeaderByToken(accessToken: accessToken)

guard let url = URL(string: DEV_BASE_URL + urlEndpointString) else { return }

AF
.request(url,
method: .post,
parameters: parameter,
encoder: .json,
headers: header)
.responseDecodable(of: AuthResponse.self) { response in
print("response :: \(response)")
switch response.result {
case .success(let success):
print(success)
completionHandler(success)
case .failure(let error):
print(error.localizedDescription)
AF
.request(url,
method: .post,
parameters: parameter,
encoder: .json,
headers: header)
.responseDecodable(of: AuthResponse.self) { response in
print("response :: \(response)")
switch response.result {
case .success(let success):
print(success)
completionHandler(success)
case .failure(let error):
print(error.localizedDescription)
}
}
}
.resume()
.resume()

}
}
}
47 changes: 25 additions & 22 deletions KeKi/Scenes/Login/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,32 +196,35 @@ extension LoginViewController {
parameter: param,
completionHandler: { [weak self] result in

print("result :: \(result)")
// λ°œκΈ‰λ°›μ€ 토큰 μ €μž₯
let accessToken = result.result.accessToken
let refreshToken = result.result.refreshToken

UserDefaults.standard.set(email, forKey: "socialEmail")
UserDefaults.standard.set(accessToken, forKey: "accessToken")
UserDefaults.standard.set(refreshToken, forKey: "refreshToken")

let role = result.result.role
switch role {
case Role.notUser.rawValue:
self?.signup()
if let result = result.result {
print("result :: \(result)")
// λ°œκΈ‰λ°›μ€ 토큰 μ €μž₯
let accessToken = result.accessToken
let refreshToken = result.refreshToken

case Role.buyer.rawValue, Role.seller.rawValue:
APIManeger.shared.setUserInfo(userInfo: result.result)
UserDefaults.standard.set(email, forKey: "socialEmail")
UserDefaults.standard.set(accessToken, forKey: "accessToken")
UserDefaults.standard.set(refreshToken, forKey: "refreshToken")

let encoder = JSONEncoder()
if let encoded = try? encoder.encode(result.result) {
UserDefaults.standard.setValue(encoded, forKey: "userInfo")
let role = result.role
switch role {
case Role.notUser.rawValue:
self?.signup()

case Role.buyer.rawValue, Role.seller.rawValue:
APIManeger.shared.setUserInfo(userInfo: result)

let encoder = JSONEncoder()
if let encoded = try? encoder.encode(result) {
UserDefaults.standard.setValue(encoded, forKey: "userInfo")
}
self?.showMain()

default:
print("μ•Œ 수 μ—†λŠ” μœ μ €")
}
self?.showMain()

default:
print("μ•Œ 수 μ—†λŠ” μœ μ €")
}

})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ extension SellerProfileSetViewController {
dataType: Seller.self,
parameter: param,
completionHandler: { [weak self] response in
print("signupRequest response :: \(response)")
switch response.code {
case 1000:
print("νšŒμ›κ°€μž… 성곡")
Expand Down

0 comments on commit 35faf4b

Please sign in to comment.