diff --git a/NADA-iOS-forRelease/Resouces/Constants/UserDefaults.swift b/NADA-iOS-forRelease/Resouces/Constants/UserDefaults.swift index f0628d1d..e138bc02 100644 --- a/NADA-iOS-forRelease/Resouces/Constants/UserDefaults.swift +++ b/NADA-iOS-forRelease/Resouces/Constants/UserDefaults.swift @@ -12,6 +12,7 @@ extension Const { static let darkModeState = "darkModeState" static let accessToken = "accessToken" static let refreshToken = "refreshToken" - static let userID = "userID" +// static let userID = "userID" + static let userID = "nada2" } } diff --git a/NADA-iOS-forRelease/Resouces/Extensions/UIViewController+Extension.swift b/NADA-iOS-forRelease/Resouces/Extensions/UIViewController+Extension.swift index 58236a0f..fcced0fd 100644 --- a/NADA-iOS-forRelease/Resouces/Extensions/UIViewController+Extension.swift +++ b/NADA-iOS-forRelease/Resouces/Extensions/UIViewController+Extension.swift @@ -80,6 +80,10 @@ extension UIViewController { toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85, y: self.view.frame.size.height/2, width: 170, height: 35)) + case "wrongCard": + toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 120, + y: self.view.frame.size.height/2, + width: 240, height: 35)) default: toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85, y: self.view.frame.size.height - 230, @@ -95,7 +99,7 @@ extension UIViewController { toastLabel.layer.cornerRadius = 10 toastLabel.clipsToBounds = true self.view.addSubview(toastLabel) - UIView.animate(withDuration: 2.0, delay: 0.1, + UIView.animate(withDuration: 3.0, delay: 0.1, options: .curveEaseOut, animations: { toastLabel.alpha = 0.0 }, completion: {_ in toastLabel.removeFromSuperview() }) } diff --git a/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.swift b/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.swift index 5cddc132..87d8b714 100644 --- a/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.swift +++ b/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.swift @@ -19,6 +19,8 @@ class CardInGroupCollectionViewCell: UICollectionViewCell { @IBOutlet weak var instagramIDLabel: UILabel! @IBOutlet weak var lineURLLabel: UILabel! + @IBOutlet weak var instagramIcon: UIImageView! + @IBOutlet weak var urlIcon: UIImageView! var groupId: Int? var cardId: String? diff --git a/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.xib b/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.xib index 290c1f3b..b03e2b1c 100644 --- a/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.xib +++ b/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.xib @@ -1,9 +1,9 @@ - + - + @@ -152,9 +152,11 @@ + + diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/AddWithIdBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/AddWithIdBottomSheetViewController.swift index b313a4ca..6a3a976a 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/AddWithIdBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/AddWithIdBottomSheetViewController.swift @@ -97,7 +97,49 @@ extension AddWithIdBottomSheetViewController { func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() // 서버 연결과 더불어... 검색 결과가 없으면 bottomsheet dismiss 하지 말고 hidden 풀어주기 - hideBottomSheetAndPresent(nextBottomSheet: CardResultBottomSheetViewController(), title: "이채연", height: 574) + cardDetailFetchWithAPI(cardID: textField.text ?? "") return true } } + +extension AddWithIdBottomSheetViewController { + func cardDetailFetchWithAPI(cardID: String) { + CardAPI.shared.cardDetailFetch(cardID: cardID) { response in + switch response { + case .success(let data): + if let card = data as? CardClass { + //TODO: 내가 쓴거 내가 추가 하면 예외처리 필요 + let nextVC = CardResultBottomSheetViewController() + nextVC.cardDataModel = Card(cardID: card.card.cardID, + background: card.card.background, + title: card.card.title, + name: card.card.name, + birthDate: card.card.birthDate, + mbti: card.card.mbti, + instagram: card.card.instagram, + link: card.card.link, + cardDescription: card.card.cardDescription, + isMincho: card.card.isMincho, + isSoju: card.card.isSoju, + isBoomuk: card.card.isBoomuk, + isSauced: card.card.isSauced, + oneTmi: card.card.oneTmi, + twoTmi: card.card.twoTmi, + threeTmi: card.card.threeTmi) + self.hideBottomSheetAndPresent(nextBottomSheet: nextVC, title: card.card.name, height: 574) + } + case .requestErr(let message): + print("cardDetailFetchWithAPI - requestErr: \(message)") + self.errorImageView.isHidden = false + self.explainLabel.isHidden = false + case .pathErr: + print("cardDetailFetchWithAPI - pathErr") + case .serverErr: + print("cardDetailFetchWithAPI - serverErr") + case .networkFail: + print("cardDetailFetchWithAPI - networkFail") + } + } + } +} + diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardResultBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardResultBottomSheetViewController.swift index f814a09e..4eb1fbc8 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardResultBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardResultBottomSheetViewController.swift @@ -11,16 +11,17 @@ import IQKeyboardManagerSwift class CardResultBottomSheetViewController: CommonBottomSheetViewController { // MARK: - Properties + var cardDataModel: Card? + private let groupLabel: UILabel = { let label = UILabel() - label.text = "어쩌구 동아리 명함" label.textColor = .secondary label.font = .textRegular03 return label }() - private let cardView: UIView = { + private let cardView: CardView = { let view = CardView() return view }() @@ -46,6 +47,27 @@ class CardResultBottomSheetViewController: CommonBottomSheetViewController { view.addSubview(cardView) view.addSubview(addButton) setupLayout() + + groupLabel.text = cardDataModel?.cardDescription + setCardView() + } + + private func setCardView() { + cardView.backgroundImageView.updateServerImage(cardDataModel?.background ?? "") + cardView.titleLabel.text = cardDataModel?.title ?? "" + cardView.descriptionLabel.text = cardDataModel?.cardDescription ?? "" + cardView.userNameLabel.text = cardDataModel?.name ?? "" + cardView.birthLabel.text = cardDataModel?.birthDate ?? "" + cardView.mbtiLabel.text = cardDataModel?.mbti ?? "" + cardView.instagramIDLabel.text = cardDataModel?.instagram ?? "" + cardView.lineURLLabel.text = cardDataModel?.link ?? "" + + if cardDataModel?.instagram == ""{ + cardView.instagramIcon.isHidden = true + } + if cardDataModel?.link == ""{ + cardView.urlIcon.isHidden = true + } } // 레이아웃 세팅 @@ -74,10 +96,32 @@ class CardResultBottomSheetViewController: CommonBottomSheetViewController { } @objc func presentGroupSelectBottomSheet() { - let nextVC = SelectGroupBottomSheetViewController() - nextVC.status = .add - hideBottomSheetAndPresent(nextBottomSheet: nextVC, title: "그룹선택", height: 386) - print("next bottomsheet") + groupListFetchWithAPI(userID: Const.UserDefaults.userID) } } + +extension CardResultBottomSheetViewController { + func groupListFetchWithAPI(userID: String) { + GroupAPI.shared.groupListFetch(userID: userID) { response in + switch response { + case .success(let data): + if let group = data as? Groups { + let nextVC = SelectGroupBottomSheetViewController() + nextVC.status = .add + nextVC.cardDataModel = self.cardDataModel + nextVC.serverGroups = group + self.hideBottomSheetAndPresent(nextBottomSheet: nextVC, title: "그룹선택", height: 386) + } + case .requestErr(let message): + print("groupListFetchWithAPI - requestErr: \(message)") + case .pathErr: + print("groupListFetchWithAPI - pathErr") + case .serverErr: + print("groupListFetchWithAPI - serverErr") + case .networkFail: + print("groupListFetchWithAPI - networkFail") + } + } + } +} diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/SelectGroupBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/SelectGroupBottomSheetViewController.swift index 843827e5..ab682b71 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/SelectGroupBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/SelectGroupBottomSheetViewController.swift @@ -10,8 +10,9 @@ import UIKit class SelectGroupBottomSheetViewController: CommonBottomSheetViewController { // MARK: - Properties - var groupList = ["미분류", "SOPT", "동아리", "인하대학교"] - var selectedGroup = "" + var cardDataModel: Card? + var serverGroups: Groups? + var selectedGroup = 0 enum Status { case detail case add @@ -44,7 +45,7 @@ class SelectGroupBottomSheetViewController: CommonBottomSheetViewController { private func setupUI() { view.addSubview(groupPicker) view.addSubview(doneButton) - selectedGroup = groupList[0] + selectedGroup = serverGroups?.groups[0].groupID ?? 0 groupPicker.delegate = self groupPicker.dataSource = self setupLayout() @@ -77,10 +78,10 @@ class SelectGroupBottomSheetViewController: CommonBottomSheetViewController { hideBottomSheetAndGoBack() case .add: print(selectedGroup) - - 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 - hideBottomSheetAndPresentVC(nextViewController: nextVC) +// 그룹 속 명함 추가 테스트 + cardAddInGroupWithAPI(cardRequest: CardAddInGroupRequest(cardId: cardDataModel?.cardID ?? "", + userId: Const.UserDefaults.userID, + groupId: selectedGroup)) } } @@ -92,7 +93,7 @@ extension SelectGroupBottomSheetViewController: UIPickerViewDelegate, UIPickerVi } func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { - return groupList.count + return serverGroups?.groups.count ?? 1 } func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { @@ -101,16 +102,16 @@ extension SelectGroupBottomSheetViewController: UIPickerViewDelegate, UIPickerVi label.textAlignment = .center if pickerView.selectedRow(inComponent: component) == row { - label.attributedText = NSAttributedString(string: groupList[row], attributes: [NSAttributedString.Key.font: UIFont.textBold01, NSAttributedString.Key.foregroundColor: UIColor.mainColorNadaMain]) + label.attributedText = NSAttributedString(string: serverGroups?.groups[row].groupName ?? "", attributes: [NSAttributedString.Key.font: UIFont.textBold01, NSAttributedString.Key.foregroundColor: UIColor.mainColorNadaMain]) } else { - label.attributedText = NSAttributedString(string: groupList[row], attributes: [NSAttributedString.Key.font: UIFont.textRegular03, NSAttributedString.Key.foregroundColor: UIColor.quaternary]) + label.attributedText = NSAttributedString(string: serverGroups?.groups[row].groupName ?? "", attributes: [NSAttributedString.Key.font: UIFont.textRegular03, NSAttributedString.Key.foregroundColor: UIColor.quaternary]) } return label } func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { - selectedGroup = groupList[row] + selectedGroup = serverGroups?.groups[row].groupID ?? 0 pickerView.reloadAllComponents() } @@ -122,3 +123,26 @@ extension SelectGroupBottomSheetViewController: UIPickerViewDelegate, UIPickerVi return 200 } } + +extension SelectGroupBottomSheetViewController { + func cardAddInGroupWithAPI(cardRequest: CardAddInGroupRequest) { + GroupAPI.shared.cardAddInGroup(cardRequest: cardRequest) { response in + switch response { + case .success: + 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 + self.hideBottomSheetAndPresentVC(nextViewController: nextVC) + case .requestErr(let message): + print("postCardAddInGroupWithAPI - requestErr", message) + self.showToast(message: message as? String ?? "", font: UIFont.button03, view: "wrongCard") + case .pathErr: + print("postCardAddInGroupWithAPI - pathErr") + case .serverErr: + print("postCardAddInGroupWithAPI - serverErr") + case .networkFail: + print("postCardAddInGroupWithAPI - networkFail") + } + } + } +} diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/CardDetail/CardDetailViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/CardDetail/CardDetailViewController.swift index 1daded7f..26dc4d2b 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/CardDetail/CardDetailViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/CardDetail/CardDetailViewController.swift @@ -22,6 +22,7 @@ class CardDetailViewController: UIViewController { self.navigationController?.popViewController(animated: true) case .add: self.dismiss(animated: true, completion: nil) + presentingViewController?.viewWillAppear(true) } } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/Group/GroupViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/Group/GroupViewController.swift index 0e031522..9630ff5e 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/Group/GroupViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/Group/GroupViewController.swift @@ -70,6 +70,7 @@ class GroupViewController: UIViewController { super.viewDidLoad() registerCell() setUI() + print(Const.UserDefaults.userID) // groupListFetchWithAPI(userID: Const.UserDefaults.userID) // 그룹 삭제 서버 테스트 // groupDeleteWithAPI(groupID: 1) @@ -77,8 +78,6 @@ class GroupViewController: UIViewController { // groupAddWithAPI(groupRequest: GroupAddRequest(userId: "nada2", groupName: "대학교")) // 그룹 수정 서버 테스트 // groupEditWithAPI(groupRequest: GroupEditRequest(groupId: 5, groupName: "수정나다")) -// 그룹 속 명함 추가 테스트 -// cardAddInGroupWithAPI(cardRequest: CardAddInGroupRequest(cardId: "cardA", userId: "nada2", groupId: 1)) // 그룹 속 명함 조회 테스트 // cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada", groupId: 5, offset: 0)) // 명함 검색 테스트 @@ -88,7 +87,7 @@ class GroupViewController: UIViewController { override func viewWillAppear(_ animated: Bool) { // 그룹 리스트 조회 서버 테스트 - groupListFetchWithAPI(userID: "nada2") + groupListFetchWithAPI(userID: Const.UserDefaults.userID) } } @@ -122,8 +121,8 @@ extension GroupViewController { self.groupCollectionView.reloadData() self.groupId = group.groups[0].groupID if !group.groups.isEmpty { - self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada2", groupId: group.groups[0].groupID, offset: 0)) -// self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: Const.UserDefaults.userID, groupId: group.groups[0].groupID, offset: 0)) +// self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada2", groupId: group.groups[0].groupID, offset: 0)) + self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: Const.UserDefaults.userID, groupId: group.groups[0].groupID, offset: 0)) } } case .requestErr(let message): @@ -251,23 +250,6 @@ extension GroupViewController { } } } - - func cardAddInGroupWithAPI(cardRequest: CardAddInGroupRequest) { - GroupAPI.shared.cardAddInGroup(cardRequest: cardRequest) { response in - switch response { - case .success: - print("postCardAddInGroupWithAPI - success") - case .requestErr(let message): - print("postCardAddInGroupWithAPI - requestErr", message) - case .pathErr: - print("postCardAddInGroupWithAPI - pathErr") - case .serverErr: - print("postCardAddInGroupWithAPI - serverErr") - case .networkFail: - print("postCardAddInGroupWithAPI - networkFail") - } - } - } } // MARK: - UICollectionViewDelegate @@ -316,6 +298,13 @@ extension GroupViewController: UICollectionViewDataSource { cardCell.instagramIDLabel.text = serverCards?.cards[indexPath.row].instagram cardCell.lineURLLabel.text = serverCards?.cards[indexPath.row].link + if serverCards?.cards[indexPath.row].instagram == "" { + cardCell.instagramIcon.isHidden = true + } + if serverCards?.cards[indexPath.row].link == "" { + cardCell.urlIcon.isHidden = true + } + return cardCell default: return UICollectionViewCell() diff --git a/NADA-iOS-forRelease/Sources/Views/CardView.swift b/NADA-iOS-forRelease/Sources/Views/CardView.swift index 3b9e05f4..35ff0732 100644 --- a/NADA-iOS-forRelease/Sources/Views/CardView.swift +++ b/NADA-iOS-forRelease/Sources/Views/CardView.swift @@ -19,6 +19,9 @@ class CardView: UIView { @IBOutlet weak var instagramIDLabel: UILabel! @IBOutlet weak var lineURLLabel: UILabel! + @IBOutlet weak var instagramIcon: UIImageView! + @IBOutlet weak var urlIcon: UIImageView! + override init(frame: CGRect) { super.init(frame: frame) xibSetup() diff --git a/NADA-iOS-forRelease/Sources/Views/CardView.xib b/NADA-iOS-forRelease/Sources/Views/CardView.xib index ca300bf7..25126881 100644 --- a/NADA-iOS-forRelease/Sources/Views/CardView.xib +++ b/NADA-iOS-forRelease/Sources/Views/CardView.xib @@ -21,9 +21,11 @@ + + @@ -34,39 +36,44 @@ + + + + +