diff --git a/NADA-iOS-forRelease/Resouces/Constants/Notification.swift b/NADA-iOS-forRelease/Resouces/Constants/Notification.swift index fe6829fc..2ef63808 100644 --- a/NADA-iOS-forRelease/Resouces/Constants/Notification.swift +++ b/NADA-iOS-forRelease/Resouces/Constants/Notification.swift @@ -16,4 +16,6 @@ extension Notification.Name { static let dismissRequiredBottomSheet = Notification.Name("dismissRequiredBottomSheet") static let cancelImagePicker = Notification.Name("cancelImagePicker") static let presentCardShare = Notification.Name("presentCardShare") + static let passDataToGroup = Notification.Name("passDataToGroup") + static let passDataToDetail = Notification.Name("passDataToDetail") } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/SelectGroupBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/SelectGroupBottomSheetViewController.swift index 41333c81..98d80f74 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/SelectGroupBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/SelectGroupBottomSheetViewController.swift @@ -13,6 +13,8 @@ class SelectGroupBottomSheetViewController: CommonBottomSheetViewController { var cardDataModel: Card? var serverGroups: Groups? var selectedGroup = 0 + var selectedGroupIndex = 0 + var groupId: Int? enum Status { case detail case add @@ -74,11 +76,11 @@ class SelectGroupBottomSheetViewController: CommonBottomSheetViewController { @objc func presentCardInfoViewController() { switch status { case .detail: - // TODO: 그룹 변경 서버통신 - hideBottomSheetAndGoBack() + changeGroupWithAPI(request: ChangeGroupRequest(cardID: cardDataModel?.cardID ?? "", + userID: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "", + groupID: groupId ?? 0, + newGroupID: selectedGroup)) case .add: - print(selectedGroup) -// 그룹 속 명함 추가 테스트 cardAddInGroupWithAPI(cardRequest: CardAddInGroupRequest(cardId: cardDataModel?.cardID ?? "", userId: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "", groupId: selectedGroup)) @@ -112,6 +114,7 @@ extension SelectGroupBottomSheetViewController: UIPickerViewDelegate, UIPickerVi func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { selectedGroup = serverGroups?.groups[row].groupID ?? 0 + selectedGroupIndex = row pickerView.reloadAllComponents() } @@ -132,6 +135,9 @@ extension SelectGroupBottomSheetViewController { guard let nextVC = UIStoryboard.init(name: Const.Storyboard.Name.cardDetail, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.cardDetailViewController) as? CardDetailViewController else { return } nextVC.status = .add nextVC.cardDataModel = self.cardDataModel + nextVC.groupId = self.selectedGroup + nextVC.serverGroups = self.serverGroups + NotificationCenter.default.post(name: Notification.Name.passDataToGroup, object: self.selectedGroupIndex, userInfo: nil) self.hideBottomSheetAndPresentVC(nextViewController: nextVC) case .requestErr(let message): print("postCardAddInGroupWithAPI - requestErr", message) @@ -145,4 +151,23 @@ extension SelectGroupBottomSheetViewController { } } } + + func changeGroupWithAPI(request: ChangeGroupRequest) { + GroupAPI.shared.changeCardGroup(request: request) { response in + switch response { + case .success: + NotificationCenter.default.post(name: Notification.Name.passDataToGroup, object: self.selectedGroupIndex, userInfo: nil) + NotificationCenter.default.post(name: Notification.Name.passDataToDetail, object: self.selectedGroup, userInfo: nil) + self.hideBottomSheetAndGoBack() + case .requestErr(let message): + print("changeGroupWithAPI - requestErr: \(message)") + case .pathErr: + print("changeGroupWithAPI - pathErr") + case .serverErr: + print("changeGroupWithAPI - serverErr") + case .networkFail: + print("changeGroupWithAPI - networkFail") + } + } + } } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/CardCreation/CardCreationViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/CardCreation/CardCreationViewController.swift index aa5b731a..6f08d2e6 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/CardCreation/CardCreationViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/CardCreation/CardCreationViewController.swift @@ -244,23 +244,6 @@ extension CardCreationViewController { // } // } - // TODO: - group 서버통신. 위치변경. -// func changeGroupWithAPI(request: ChangeGroupRequest) { -// GroupAPI.shared.changeCardGroup(request: request) { response in -// switch response { -// case .success: -// print("changeGroupWithAPI - success") -// case .requestErr(let message): -// print("changeGroupWithAPI - requestErr: \(message)") -// case .pathErr: -// print("changeGroupWithAPI - pathErr") -// case .serverErr: -// print("changeGroupWithAPI - serverErr") -// case .networkFail: -// print("changeGroupWithAPI - networkFail") -// } -// } -// } // TODO: - group 서버통신. 위치변경. // func cardDeleteInGroupWithAPI(groupID: Int, cardID: String) { // GroupAPI.shared.cardDeleteInGroup(groupID: groupID, cardID: cardID) { response in diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/CardDetail/CardDetailViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/CardDetail/CardDetailViewController.swift index 26dc4d2b..3458d668 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/CardDetail/CardDetailViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/CardDetail/CardDetailViewController.swift @@ -44,6 +44,7 @@ class CardDetailViewController: UIViewController { private var isFront = true var status: Status = .group + var serverGroups: Groups? var groupId: Int? override func viewDidLoad() { @@ -54,6 +55,9 @@ class CardDetailViewController: UIViewController { setGestureRecognizer() } + override func viewWillAppear(_ animated: Bool) { + NotificationCenter.default.addObserver(self, selector: #selector(didRecieveDataNotification(_:)), name: Notification.Name.passDataToDetail, object: nil) + } } extension CardDetailViewController { @@ -94,6 +98,9 @@ extension CardDetailViewController { .setTitle("그룹선택") .setHeight(386) nextVC.status = .detail + nextVC.groupId = self.groupId + nextVC.serverGroups = self.serverGroups + nextVC.cardDataModel = self.cardDataModel nextVC.modalPresentationStyle = .overFullScreen self.present(nextVC, animated: false, completion: nil) }) @@ -142,6 +149,10 @@ extension CardDetailViewController { // MARK: - @objc Methods + @objc func didRecieveDataNotification(_ notification: Notification) { + groupId = notification.object as? Int ?? 0 + } + @objc private func transitionCardWithAnimation(_ swipeGesture: UISwipeGestureRecognizer) { if isFront { diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/Group/GroupViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/Group/GroupViewController.swift index f2dacc1e..648ad438 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/Group/GroupViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/Group/GroupViewController.swift @@ -66,6 +66,8 @@ class GroupViewController: UIViewController { var serverCardsWithBack: Card? var groupId: Int? + var selectedRow = 0 + override func viewDidLoad() { super.viewDidLoad() registerCell() @@ -73,7 +75,8 @@ class GroupViewController: UIViewController { // 그룹 삭제 서버 테스트 // groupDeleteWithAPI(groupID: 1) // 그룹 추가 서버 테스트 -// groupAddWithAPI(groupRequest: GroupAddRequest(userId: "nada2", groupName: "대학교")) +// groupAddWithAPI(groupRequest: GroupAddRequest(userId: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "", +// groupName: "SOPT")) // 그룹 수정 서버 테스트 // groupEditWithAPI(groupRequest: GroupEditRequest(groupId: 5, groupName: "수정나다")) // 그룹 속 명함 조회 테스트 @@ -85,7 +88,8 @@ class GroupViewController: UIViewController { override func viewWillAppear(_ animated: Bool) { // 그룹 리스트 조회 서버 테스트 -// groupListFetchWithAPI(userID: UserConst.UserDefaults.userID) + NotificationCenter.default.addObserver(self, selector: #selector(didRecieveDataNotification(_:)), name: Notification.Name.passDataToGroup, object: nil) + print("viewWillAppear") groupListFetchWithAPI(userID: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "") } @@ -107,6 +111,10 @@ extension GroupViewController { emptyView.isHidden = true navigationController?.navigationBar.isHidden = true } + + @objc func didRecieveDataNotification(_ notification: Notification) { + selectedRow = notification.object as? Int ?? 0 + } } // MARK: - Network @@ -119,10 +127,9 @@ extension GroupViewController { if let group = data as? Groups { self.serverGroups = group self.groupCollectionView.reloadData() - self.groupId = group.groups[0].groupID + self.groupId = group.groups[self.selectedRow].groupID if !group.groups.isEmpty { -// self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada2", groupId: group.groups[0].groupID, offset: 0)) - self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "", groupId: group.groups[0].groupID, offset: 0)) + self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "", groupId: group.groups[self.selectedRow].groupID, offset: 0)) } } case .requestErr(let message): @@ -237,6 +244,7 @@ extension GroupViewController { twoTmi: card.card.twoTmi, threeTmi: card.card.threeTmi) nextVC.groupId = self.groupId + nextVC.serverGroups = self.serverGroups self.navigationController?.pushViewController(nextVC, animated: true) } case .requestErr(let message): @@ -279,7 +287,7 @@ extension GroupViewController: UICollectionViewDataSource { groupCell.groupName.text = serverGroups?.groups[indexPath.row].groupName - if indexPath.row == 0 { + if indexPath.row == selectedRow { collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .init()) } return groupCell @@ -314,8 +322,12 @@ extension GroupViewController: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { switch collectionView { case groupCollectionView: + selectedRow = indexPath.row groupId = serverGroups?.groups[indexPath.row].groupID - cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada2", groupId: serverGroups?.groups[indexPath.row].groupID ?? 0, offset: 0)) + cardListInGroupWithAPI(cardListInGroupRequest: + CardListInGroupRequest(userId: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "", + groupId: serverGroups?.groups[indexPath.row].groupID ?? 0, + offset: 0)) case cardsCollectionView: cardDetailFetchWithAPI(cardID: serverCards?.cards[indexPath.row].cardID ?? "") default: