Skip to content

Commit

Permalink
refactor: mainVC 화면 load시 유저 정보 조회 api 실행으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
heejinnn committed Jan 16, 2024
1 parent d08454b commit 54e6e53
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 46 deletions.
Binary file not shown.
36 changes: 1 addition & 35 deletions fit-a-pet-client/fit-a-pet-client/ViewControllers/LoginVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ class LoginVC: UIViewController{
print("userId: \(userId)")
UserDefaults.standard.set(userId, forKey: "id")

self?.fetchUserProfileInfo(completion: {
self?.present(mainVC, animated: false, completion: nil)
})
self?.present(mainVC, animated: false, completion: nil)
}
}
} catch {
Expand All @@ -192,38 +190,6 @@ class LoginVC: UIViewController{
}
}
}

func fetchUserProfileInfo(completion: @escaping () -> Void) {

AuthorizationAlamofire.shared.userProfileInfo { userProfileResult in
switch userProfileResult {
case .success(let data):
if let responseData = data {
do {
let jsonObject = try JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] ?? [:]

if let dataDict = jsonObject["data"] as? [String: Any],
let memberDict = dataDict["member"] as? [String: Any] {

for (key, value) in memberDict {
UserDefaults.standard.set(value, forKey: key)
}

UserDefaults.standard.synchronize()
}
print("Response JSON Data: \(jsonObject)")
} catch {
print("Error parsing user profile JSON: \(error)")
}
}

case .failure(let profileError):
print("Error fetching user profile info: \(profileError)")
}

completion()
}
}

@objc func changeFindIdVC(_ sender: UIButton){
FindIdPwSwitch.findAuth = "아이디 찾기"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,14 @@ class MainVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

// self.navigationItem.title = "반려동물 등록하기"

petCollectionView.delegate = self
petCollectionView.dataSource = self

layoutScrollView.delegate = self

initView()

// if let cookies = HTTPCookieStorage.shared.cookies {
// for cookie in cookies {
// print("Cookie description: \(cookie.description)")
// // You can access other properties of the cookie here
// }
// }

fetchUserProfileInfo()

}
private func initView(){
Expand Down Expand Up @@ -140,8 +133,37 @@ class MainVC: UIViewController {
let nextVC = InputSpeciesVC(title: "반려동물 등록하기")
nextVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(nextVC, animated: false)


}

func fetchUserProfileInfo() {

AuthorizationAlamofire.shared.userProfileInfo { userProfileResult in
switch userProfileResult {
case .success(let data):
if let responseData = data {
do {
let jsonObject = try JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] ?? [:]

if let dataDict = jsonObject["data"] as? [String: Any],
let memberDict = dataDict["member"] as? [String: Any] {

for (key, value) in memberDict {
UserDefaults.standard.set(value, forKey: key)
}

UserDefaults.standard.synchronize()
}
print("Response JSON Data: \(jsonObject)")
} catch {
print("Error parsing user profile JSON: \(error)")
}
}

case .failure(let profileError):
print("Error fetching user profile info: \(profileError)")
}

}
}
}

Expand Down

0 comments on commit 54e6e53

Please sign in to comment.