Skip to content
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

Merged
merged 28 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e9a8fa3
Merge branch 'release/#180' into release/#184
mini-min Dec 21, 2021
c915aa5
[FEAT] #184 - 메인 뷰 서버연결
mini-min Dec 21, 2021
95a4a7c
[FEAT] #184 - 카드 리스트용 모델 수정
mini-min Dec 21, 2021
2fa8937
Merge branch 'release1.0/1' into release/#184
mini-min Dec 21, 2021
7998ff4
Merge branch 'TeamNADA:release1.0/1' into release/#184
mini-min Dec 21, 2021
68eab89
[FEAT] #184 - 카드 리스트 핀 되어있는 명함은 스와이프 불가능하도록 변경
mini-min Dec 21, 2021
86da01d
[FIX] #184 - 로그아웃, 삭제하기 rootVC 수정하도록 변경
mini-min Dec 21, 2021
10a1aea
Merge branch 'release1.0/1' into release/#184
mini-min Dec 21, 2021
4aaf176
[FEAT] #184 - 리스트 서버 중간작업
mini-min Dec 22, 2021
9c751de
Merge branch 'release/#199' into release/#184
mini-min Dec 22, 2021
0c0fa12
[FEAT] #184 - 카드 리스트 로직 수정
mini-min Dec 23, 2021
08dba33
Merge branch 'release1.0/1' into release/#184
mini-min Dec 23, 2021
6b680f3
[FEAT] #184 - 핀 수정시 카드 리스트 편집 로직 추가
mini-min Dec 23, 2021
127cd07
[FEAT] #184 - 카드 삭제 서버 연결
mini-min Dec 23, 2021
83efd11
[FEAT] #184 - 카드 리스트 뷰 조회 서버 연결
mini-min Dec 23, 2021
deb99a2
[FEAT] #184 - 카드 위치 수정 작업중
mini-min Dec 23, 2021
78ed43d
Merge branch 'release1.0/1' into release/#184
mini-min Dec 23, 2021
d4384f4
Merge branch 'release1.0/1' into release/#184
mini-min Dec 24, 2021
6d3612c
[FEAT] #184 - 테이블뷰 리로드 위치 수정
mini-min Dec 24, 2021
d4665af
Merge branch 'release1.0/2' into release/#184
mini-min Dec 26, 2021
0facb14
[TEST] #184 - 메인 서버 테스트
mini-min Dec 26, 2021
bca7d71
[FEAT] #184 - 카드 리스트 삭제 구현 완료
mini-min Dec 26, 2021
a80c8b6
[FIX] #184 - 카드 리스트 편집 버그 발견
mini-min Dec 26, 2021
0dc5e56
[FEAT] #184 - 핀 고정시 명함 순서 편집 로직구현 & 애니메이션 추가 완료
mini-min Dec 26, 2021
845d44c
[FEAT] #184 - 드래그 시 명함 순서 편집 로직 구현
mini-min Dec 26, 2021
26db57b
[FEAT] #184 - 리스트 뷰 UserDefaults로 변경
mini-min Dec 26, 2021
145e461
[FEAT] #184 - 리스트 뷰 UserDefaults 추가 변경 부분
mini-min Dec 26, 2021
e173613
[FIX] #184 - 코드리뷰 반영 수정
mini-min Dec 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ extension UIViewController {
switch view {
case "QRScan":
toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85,
y: self.view.frame.size.height - 230,
width: 170, height: 35))
y: self.view.frame.size.height - 230,
width: 170, height: 35))
case "copyID":
toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 100,
y: self.view.frame.size.height/2,
width: 200, height: 35))
y: self.view.frame.size.height/2,
width: 200, height: 35))
case "saveImage":
toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85,
y: self.view.frame.size.height/2,
Expand All @@ -86,8 +86,8 @@ extension UIViewController {
width: 240, height: 35))
default:
toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85,
y: self.view.frame.size.height - 230,
width: 170, height: 35))
y: self.view.frame.size.height - 230,
width: 170, height: 35))
}

toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
Expand All @@ -103,4 +103,16 @@ extension UIViewController {
options: .curveEaseOut, animations: { toastLabel.alpha = 0.0 },
completion: {_ in toastLabel.removeFromSuperview() })
}

// MARK: UIWindow의 rootViewController를 변경하여 화면전환
func changeRootViewController(_ viewControllerToPresent: UIViewController) {
if let window = UIApplication.shared.windows.first {
window.rootViewController = viewControllerToPresent
UIView.transition(with: window, duration: 0.5, options: .transitionCrossDissolve, animations: nil)
} else {
viewControllerToPresent.modalPresentationStyle = .overFullScreen
self.present(viewControllerToPresent, animated: true, completion: nil)
}
}
Comment on lines +108 to +116
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳굳 고민 많이 하셨을거 같네여!


}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@

import Foundation

// MARK: - CardList
// MARK: - CardListRequest
struct CardListRequest: Codable {
let cardID, title, createDate: String
let cardDates: [CardList]
}

// MARK: - CardList
struct CardList: Codable {
let cardID, title: String

enum CodingKeys: String, CodingKey {
case cardID = "cardId"
case title, createDate
case title
}
}
58 changes: 46 additions & 12 deletions NADA-iOS-forRelease/Sources/NetworkService/Card/CardAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 추가하셨군요!


case .failure(let err):
print(err)
}
}
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이제 const 에 선언해둔거 지우고 이렇게 코드 바꾸기 시작하면 될거 같아여

Copy link
Member Author

Choose a reason for hiding this comment

The 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"]
}
}
}
22 changes: 21 additions & 1 deletion NADA-iOS-forRelease/Sources/NetworkService/User/UserAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class UserAPI {
let statusCode = response.statusCode
let data = response.data

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

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

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

let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<UserWithTokenRequest>.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 judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<String>.self, from: data)
Expand Down
2 changes: 2 additions & 0 deletions NADA-iOS-forRelease/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기부분에 65 번 66 번 코드를 넣으면 될거 같네용

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 맞네요!!! ㅋㅌㅋㅌㅋㅌㅋ쓰고 까먹어버렸...감사합니돠

}
self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import KakaoSDKCommon
class CardListViewController: UIViewController {

// MARK: - Properties
var cardItems: [CardListDataModel] = []
var cardItems: [CardList] = []
var newCardItems: [Ordered] = []

// MARK: - IBOutlet Properties
@IBOutlet weak var cardListTableView: UITableView!
Expand All @@ -22,17 +23,14 @@ class CardListViewController: UIViewController {
super.viewDidLoad()

navigationBackSwipeMotion()

setCardList()
setLongPressGesture()

cardListTableView.register(CardListTableViewCell.nib(), forCellReuseIdentifier: "CardListTableViewCell")

cardListTableView.delegate = self
cardListTableView.dataSource = self

// FIXME: - 카드 리스트 조회 서버 테스트
// cardListFetchWithAPI(userID: "nada", isList: true, offset: 0)
cardListFetchWithAPI(userID: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "", isList: true)
}

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -47,17 +45,6 @@ class CardListViewController: UIViewController {
}

// MARK: - Functions
func setCardList() {
cardItems.append(contentsOf: [
CardListDataModel(title: "SOPT 28기 명함"),
CardListDataModel(title: "디자인 스터디 명함"),
CardListDataModel(title: "아이스브레이킹"),
CardListDataModel(title: "NADA 명함"),
CardListDataModel(title: "NADA 명함"),
CardListDataModel(title: "NADA 명함")
])
}

func setLongPressGesture() {
self.cardListTableView.allowsSelection = false

Expand Down Expand Up @@ -91,12 +78,16 @@ class CardListViewController: UIViewController {
let index = cardListTableView.indexPath(for: cell)

if index!.row > 0 {
cardListTableView.moveRow(at: index!, to: IndexPath(row: 0, section: 0))
self.cardItems.insert(self.cardItems.remove(at: index!.row), at: 0)
cardListTableView.reloadData()
cardListTableView.moveRow(at: index!, to: IndexPath(row: 0, section: 0))

// FIXME: - 카드 리스트 편집 서버 테스트
// self.putCardListEditWithAPI(request: CardListEditRequest(ordered: [Ordered(cardID: "cardA", priority: 1), Ordered(cardID: "cardB", priority: 0)]))
var count = 0
while cardItems.count > count {
newCardItems.append(Ordered(cardID: cardItems[count].cardID, priority: count))
count += 1
}
cardListEditWithAPI(request: CardListEditRequest(ordered: newCardItems))
}
}
}
Expand All @@ -109,20 +100,24 @@ extension CardListViewController: UITableViewDelegate {

// Swipe Action
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .normal, title: "삭제", handler: { (_ action, _ view, _ success) in
self.makeCancelDeleteAlert(title: "명함 삭제", message: "명함을 정말 삭제하시겠습니까?\n공유된 명함일 경우, 친구의 명함 모음에서도 해당 명함이 삭제됩니다.", cancelAction: { _ in
// 취소 눌렀을 때 액션이 들어갈 부분
}, deleteAction: { _ in
// FIXME: - 카드 삭제 서버 테스트
// self.deleteCardWithAPI(cardID: "cardA")
if indexPath.row == 0 {
return nil
} else {
let deleteAction = UIContextualAction(style: .normal, title: "삭제", handler: { (_ action, _ view, _ success) in
self.makeCancelDeleteAlert(title: "명함 삭제", message: "명함을 정말 삭제하시겠습니까?\n공유된 명함일 경우, 친구의 명함 모음에서도 해당 명함이 삭제됩니다.", cancelAction: { _ in
// 취소 눌렀을 때 액션이 들어갈 부분
}, deleteAction: { _ in
self.deleteCardWithAPI(cardID: self.cardItems[indexPath.row].cardID)
self.cardListTableView.reloadData()
})
})
})
deleteAction.backgroundColor = .red

let swipeActions = UISwipeActionsConfiguration(actions: [deleteAction])
swipeActions.performsFirstActionWithFullSwipe = false

return swipeActions
deleteAction.backgroundColor = .red
let swipeActions = UISwipeActionsConfiguration(actions: [deleteAction])
swipeActions.performsFirstActionWithFullSwipe = false
return swipeActions
}
}
}

Expand Down Expand Up @@ -154,12 +149,13 @@ extension CardListViewController: UITableViewDataSource {

// MARK: - Network
extension CardListViewController {
func cardListFetchWithAPI(userID: String, isList: Bool, offset: Int) {
CardAPI.shared.cardListFetch(userID: userID, isList: isList, offset: offset) { response in
func cardListFetchWithAPI(userID: String, isList: Bool) {
CardAPI.shared.cardListFetch(userID: userID, isList: isList, offset: nil) { response in
switch response {
case .success(let data):
if let card = data as? CardListRequest {
print(card)
self.cardItems = card.cardDates
self.cardListTableView.reloadData()
}
case .requestErr(let message):
print("getCardListFetchWithAPI - requestErr", message)
Expand Down Expand Up @@ -195,6 +191,8 @@ extension CardListViewController {
switch response {
case .success(let data):
print(data)
self.cardListFetchWithAPI(userID: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "", isList: true)
self.cardListTableView.reloadData()
case .requestErr(let message):
print("deleteGroupWithAPI - requestErr", message)
case .pathErr:
Expand All @@ -211,7 +209,6 @@ extension CardListViewController {

// MARK: - Extension: 테이블 뷰 Drag & Drop 기능
extension CardListViewController {
// FIX: cyclomatic_complexity 워닝 발생 -> decision이 복잡해서라는데...일단 보류...
@objc func longPressCalled(gestureRecognizer: UIGestureRecognizer) {
guard let longPress = gestureRecognizer as? UILongPressGestureRecognizer else { return }
let state = longPress.state
Expand All @@ -221,6 +218,7 @@ extension CardListViewController {
// 최초 indexPath 변수
struct Initial {
static var initialIndexPath: IndexPath?
static var tabIndex: IndexPath?
}

// 스냅샷
Expand All @@ -237,6 +235,7 @@ extension CardListViewController {
case UIGestureRecognizer.State.began:
if indexPath!.row != 0 {
Initial.initialIndexPath = indexPath
Initial.tabIndex = indexPath
var cell: UITableViewCell? = UITableViewCell()
cell = cardListTableView.cellForRow(at: indexPath!)

Expand Down Expand Up @@ -301,12 +300,16 @@ extension CardListViewController {

}, completion: { (finished) -> Void in
if finished {
var count = 0
while self.cardItems.count > count {
self.newCardItems.append(Ordered(cardID: self.cardItems[count].cardID, priority: count))
count += 1
}
self.cardListEditWithAPI(request: CardListEditRequest(ordered: self.newCardItems))

Initial.initialIndexPath = nil
MyCell.cellSnapshot!.removeFromSuperview()
MyCell.cellSnapshot = nil

// FIXME: - 카드 리스트 편집 서버 테스트
// self.putCardListEditWithAPI(request: CardListEditRequest(ordered: [Ordered(cardID: "cardA", priority: 1), Ordered(cardID: "cardB", priority: 0)]))
}
})
}
Expand Down
Loading