-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] #184 - 리스트뷰, 메인 일부 서버 연결 #225
Changes from 27 commits
e9a8fa3
c915aa5
95a4a7c
2fa8937
7998ff4
68eab89
86da01d
10a1aea
4aaf176
9c751de
0c0fa12
08dba33
6b680f3
127cd07
83efd11
deb99a2
78ed43d
d4384f4
6d3612c
d4665af
0facb14
bca7d71
a80c8b6
0dc5e56
845d44c
26db57b
145e461
e173613
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,18 +47,32 @@ public class CardAPI { | |
} | ||
} | ||
|
||
func cardListFetch(userID: String, isList: Bool, offset: Int, completion: @escaping (NetworkResult<Any>) -> Void) { | ||
func cardListFetch(userID: String, isList: Bool, offset: Int?, completion: @escaping (NetworkResult<Any>) -> Void) { | ||
cardProvider.request(.cardListFetch(userID: userID, isList: isList, offset: offset)) { (result) in | ||
switch result { | ||
case .success(let response): | ||
let statusCode = response.statusCode | ||
let data = response.data | ||
|
||
let networkResult = self.judgeCardListFetchStatus(by: statusCode, data) | ||
completion(networkResult) | ||
|
||
case .failure(let err): | ||
print(err) | ||
if isList == true { | ||
switch result { | ||
case .success(let response): | ||
let statusCode = response.statusCode | ||
let data = response.data | ||
|
||
let networkResult = self.judgeCardListFetchStatus(by: statusCode, data) | ||
completion(networkResult) | ||
|
||
case .failure(let err): | ||
print(err) | ||
} | ||
} else { | ||
switch result { | ||
case .success(let response): | ||
let statusCode = response.statusCode | ||
let data = response.data | ||
|
||
let networkResult = self.judgeMainListFetchStatus(by: statusCode, data) | ||
completion(networkResult) | ||
Comment on lines
+52
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 추가하셨군요! |
||
|
||
case .failure(let err): | ||
print(err) | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -115,7 +129,7 @@ public class CardAPI { | |
} | ||
} | ||
|
||
private func judgeCardListFetchStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> { | ||
private func judgeMainListFetchStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> { | ||
|
||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(GenericResponse<CardListLookUpRequest>.self, from: data) | ||
|
@@ -135,6 +149,26 @@ public class CardAPI { | |
} | ||
} | ||
|
||
private func judgeCardListFetchStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> { | ||
|
||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(GenericResponse<CardListRequest>.self, from: data) | ||
else { | ||
return .pathErr | ||
} | ||
|
||
switch statusCode { | ||
case 200: | ||
return .success(decodedData.data ?? "None-Data") | ||
case 400..<500: | ||
return .requestErr(decodedData.msg) | ||
case 500: | ||
return .serverErr | ||
default: | ||
return .networkFail | ||
} | ||
} | ||
|
||
private func judgeCardCreationStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> { | ||
|
||
let decoder = JSONDecoder() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,12 +111,11 @@ extension CardService: TargetType { | |
|
||
var headers: [String: String]? { | ||
switch self { | ||
case .cardDetailFetch, .cardListFetch, .cardDelete: | ||
return Const.Header.bearerHeader | ||
case .cardDetailFetch, .cardListFetch, .cardDelete, .cardListEdit: | ||
return ["Content-Type": "application/json", | ||
"Authorization": "Bearer " + UserDefaults.standard.string(forKey: Const.UserDefaults.accessToken)!] | ||
Comment on lines
+114
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이제 const 에 선언해둔거 지우고 이렇게 코드 바꾸기 시작하면 될거 같아여 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넴넴! |
||
case .cardCreation: | ||
return Const.Header.basicHeader | ||
case .cardListEdit: | ||
return ["Content-Type": "application/json"] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
|
||
if self.defaults.string(forKey: Const.UserDefaults.accessToken) != "" { | ||
rootViewController = UIStoryboard(name: Const.Storyboard.Name.tabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.tabBarViewController) | ||
} else { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기부분에 65 번 66 번 코드를 넣으면 될거 같네용 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 맞네요!!! ㅋㅌㅋㅌㅋㅌㅋ쓰고 까먹어버렸...감사합니돠 |
||
} | ||
self.window?.rootViewController = rootViewController | ||
self.window?.makeKeyAndVisible() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굳굳 고민 많이 하셨을거 같네여!