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] #201 - ID로 명함 검색해서 추가하기 서버 #202

Merged
merged 8 commits into from
Dec 23, 2021
3 changes: 2 additions & 1 deletion NADA-iOS-forRelease/Resouces/Constants/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Comment on lines +83 to 87
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85,
y: self.view.frame.size.height - 230,
Expand All @@ -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() })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
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="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<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">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -152,9 +152,11 @@
<outlet property="birthLabel" destination="WCz-jU-GLW" id="JWN-qF-cmV"/>
<outlet property="descriptionLabel" destination="RM7-A9-SfR" id="Taf-hG-9yJ"/>
<outlet property="instagramIDLabel" destination="R2H-kH-GqM" id="gNa-to-IoK"/>
<outlet property="instagramIcon" destination="XFs-Sv-f0r" id="419-Xr-AxM"/>
<outlet property="lineURLLabel" destination="oO0-od-Oxm" id="Y5l-wc-JJu"/>
<outlet property="mbtiLabel" destination="Wwx-y2-tN3" id="TN4-Or-c2j"/>
<outlet property="titleLabel" destination="Rng-0l-SgL" id="9nl-nq-ggY"/>
<outlet property="urlIcon" destination="07x-TC-A3z" id="wNd-jb-LjS"/>
<outlet property="userNameLabel" destination="tBD-lZ-HlH" id="i74-Z7-zHd"/>
</connections>
<point key="canvasLocation" x="137.68115942028987" y="78.348214285714278"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
}()
Expand All @@ -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
}
}

// 레이아웃 세팅
Expand Down Expand Up @@ -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")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}
}

Expand All @@ -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 {
Expand All @@ -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()
}

Expand All @@ -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")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CardDetailViewController: UIViewController {
self.navigationController?.popViewController(animated: true)
case .add:
self.dismiss(animated: true, completion: nil)
presentingViewController?.viewWillAppear(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ class GroupViewController: UIViewController {
super.viewDidLoad()
registerCell()
setUI()
print(Const.UserDefaults.userID)
// groupListFetchWithAPI(userID: Const.UserDefaults.userID)
// 그룹 삭제 서버 테스트
// groupDeleteWithAPI(groupID: 1)
// 그룹 추가 서버 테스트
// 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))
// 명함 검색 테스트
Expand All @@ -88,7 +87,7 @@ class GroupViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
// 그룹 리스트 조회 서버 테스트
groupListFetchWithAPI(userID: "nada2")
groupListFetchWithAPI(userID: Const.UserDefaults.userID)
}

}
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions NADA-iOS-forRelease/Sources/Views/CardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading