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] #219 - 명함 그룹 수정 서버 #220

Merged
merged 5 commits into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions NADA-iOS-forRelease/Resouces/Constants/Notification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ 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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,8 +76,12 @@ class SelectGroupBottomSheetViewController: CommonBottomSheetViewController {
@objc func presentCardInfoViewController() {
switch status {
case .detail:
// TODO: 그룹 변경 서버통신
hideBottomSheetAndGoBack()
// 그룹 변경 서버통신
print(selectedGroup)
Copy link
Member

Choose a reason for hiding this comment

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

이거 비롯해서 switch 문 안의 프린트문 지워줘도 될거같아용

Copy link
Member Author

Choose a reason for hiding this comment

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

네 주석 제거 한번더 처리하겠숨당!!

changeGroupWithAPI(request: ChangeGroupRequest(cardID: cardDataModel?.cardID ?? "",
userID: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "",
groupID: groupId ?? 0,
newGroupID: selectedGroup))
case .add:
print(selectedGroup)
// 그룹 속 명함 추가 테스트
Expand Down Expand Up @@ -112,6 +118,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()
}

Expand All @@ -132,6 +139,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.groupId
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)
Expand All @@ -145,4 +155,23 @@ extension SelectGroupBottomSheetViewController {
}
}
}

func changeGroupWithAPI(request: ChangeGroupRequest) {
GroupAPI.shared.changeCardGroup(request: request) { response in
switch response {
case .success:
print("changeGroupWithAPI - success")
NotificationCenter.default.post(name: Notification.Name.passDataToGroup, object: self.selectedGroupIndex, 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")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CardDetailViewController: UIViewController {

private var isFront = true
var status: Status = .group
var serverGroups: Groups?
var groupId: Int?

override func viewDidLoad() {
Expand Down Expand Up @@ -94,6 +95,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)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ class GroupViewController: UIViewController {
var serverCardsWithBack: Card?
var groupId: Int?

var selectedRow = 0

override func viewDidLoad() {
super.viewDidLoad()
registerCell()
setUI()
// 그룹 삭제 서버 테스트
// groupDeleteWithAPI(groupID: 1)
// 그룹 추가 서버 테스트
// groupAddWithAPI(groupRequest: GroupAddRequest(userId: "nada2", groupName: "대학교"))
// groupAddWithAPI(groupRequest: GroupAddRequest(userId: UserDefaults.standard.string(forKey: Const.UserDefaults.userID) ?? "",
// groupName: "SOPT"))
Comment on lines +78 to +79
Copy link
Member

Choose a reason for hiding this comment

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

테스트 끝났으면 정리해주세욥!

Copy link
Member Author

Choose a reason for hiding this comment

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

앗 요거는 제가 임의로 그룹 추가할때 포스트맨 대신 서버 붙인걸로 쏜거라서... 민재가 아마 그룹 추가할때 필요할거에욤 !!

Copy link
Member

Choose a reason for hiding this comment

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

아아 그래욥! 최고!

// 그룹 수정 서버 테스트
// groupEditWithAPI(groupRequest: GroupEditRequest(groupId: 5, groupName: "수정나다"))
// 그룹 속 명함 조회 테스트
Expand All @@ -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) ?? "")

}
Expand All @@ -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
Expand All @@ -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))
Copy link
Member

Choose a reason for hiding this comment

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

일단 오프셋 0으로 확인요!! 수고했습니당

}
}
case .requestErr(let message):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down