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] #140 - 명함 그룹 뷰 서버연결 #188

Merged
merged 6 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<connections>
<outlet property="backButton" destination="ppy-17-v7q" id="mdc-dd-yGB"/>
<outlet property="cardView" destination="0P6-1k-dQm" id="qGN-9y-K4Y"/>
<outlet property="idLabel" destination="J0e-kR-6Zc" id="4il-d0-UMv"/>
<outlet property="optionButton" destination="YU7-vs-utH" id="Jg4-K3-dTV"/>
</connections>
</viewController>
Expand Down
6 changes: 3 additions & 3 deletions NADA-iOS-forRelease/Sources/Cells/CardCell/MainCardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ extension MainCardCell {
cardDataModel.isSoju,
cardDataModel.isBoomuk,
cardDataModel.isSauced,
cardDataModel.oneTMI ?? "",
cardDataModel.twoTMI ?? "",
cardDataModel.thirdTMI ?? "",
cardDataModel.oneTmi ?? "",
cardDataModel.twoTmi ?? "",
cardDataModel.threeTmi ?? "",
isShareable: isShareable ?? false)

contentView.addSubview(backCard)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class CardInGroupCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var instagramIDLabel: UILabel!
@IBOutlet weak var lineURLLabel: UILabel!

var groupId: Int?
var cardId: String?

override func awakeFromNib() {
super.awakeFromNib()
setUI()
Expand Down
18 changes: 13 additions & 5 deletions NADA-iOS-forRelease/Sources/NetworkModel/Card/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@

import Foundation

// MARK: - DataClass
struct CardClass: Codable {
let card: Card
}

Comment on lines +10 to +14
Copy link
Member

Choose a reason for hiding this comment

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

화긴했습니다 감사합니다!

// MARK: - Card
struct Card: Codable {
let cardID, background, title, name, birthDate, mbti: String
let instagram, link, cardDescription: String?
let cardID, background, title, name: String
let birthDate, mbti, instagram, link: String
let cardDescription: String
let isMincho, isSoju, isBoomuk, isSauced: Bool
let oneTMI, twoTMI, thirdTMI: String?
let oneTmi, twoTmi, threeTmi: String

enum CodingKeys: String, CodingKey {
case cardID = "cardId"
case background, title, name, birthDate, mbti, instagram, link, isMincho, isSoju, isBoomuk, isSauced, oneTMI, twoTMI, thirdTMI
case background, title, name, birthDate, mbti, instagram, link
case cardDescription = "description"
case isMincho, isSoju, isBoomuk, isSauced, oneTmi, twoTmi, threeTmi
}
}
// FIXME: - 메인에서 카드 정보 정적으로 생성하기 위한 주석
// init(from decoder: Decoder) throws {
// let values = try decoder.container(keyedBy: CodingKeys.self)
Expand All @@ -39,4 +47,4 @@ struct Card: Codable {
// twoTMI = (try? values.decode(String.self, forKey: .twoTMI))
// thirdTMI = (try? values.decode(String.self, forKey: .thirdTMI))
// }
}
//}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class CardAPI {
private func judgeCardDetailFetchStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {

let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<Card>.self, from: data)
guard let decodedData = try? decoder.decode(GenericResponse<CardClass>.self, from: data)
else {
return .pathErr
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extension CardService: TargetType {
var headers: [String: String]? {
switch self {
case .cardDetailFetch, .cardListFetch, .cardDelete:
return .none
return Const.Header.bearerHeader
case .cardCreation:
return ["Content-Type": "multipart/form-data"]
case .cardListEdit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CardDetailViewController: UIViewController {
@IBOutlet weak var optionButton: UIButton!
@IBOutlet weak var cardView: UIView!
@IBOutlet weak var backButton: UIButton!
@IBOutlet weak var idLabel: UILabel!

public var cardDataModel: Card?
private var isShareable: Bool = false
Expand All @@ -61,6 +62,7 @@ extension CardDetailViewController {
case .add:
backButton.setImage(UIImage(named: "iconClear"), for: .normal)
}
idLabel.text = cardDataModel?.cardID
}
private func setMenu() {
let changeGroup = UIAction(title: "그룹 변경",
Expand Down Expand Up @@ -126,9 +128,9 @@ extension CardDetailViewController {
cardDataModel?.isSoju ?? true,
cardDataModel?.isBoomuk ?? true,
cardDataModel?.isSauced ?? true,
cardDataModel?.oneTMI ?? "",
cardDataModel?.twoTMI ?? "",
cardDataModel?.thirdTMI ?? "",
cardDataModel?.oneTmi ?? "",
cardDataModel?.twoTmi ?? "",
cardDataModel?.threeTmi ?? "",
isShareable: isShareable)

cardView.addSubview(backCard)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Photos
import UIKit
import Kingfisher

class GroupViewController: UIViewController {

Expand Down Expand Up @@ -59,24 +60,26 @@ class GroupViewController: UIViewController {
@IBOutlet weak var cardsCollectionView: UICollectionView!

// 그룹 이름들을 담을 변수 생성
var groups = ["미분류", "SOPT", "그룹명엄청길어요이거", "인하대학교"]
var serverGroups: Groups?
var serverCards: CardsInGroupResponse?
var serverCardsWithBack: Card?

override func viewDidLoad() {
super.viewDidLoad()
registerCell()
setUI()
// 그룹 리스트 조회 서버 테스트
// groupListFetchWithAPI(userID: "nada")
groupListFetchWithAPI(userID: "nada")
// 그룹 삭제 서버 테스트
// groupDeleteWithAPI(groupID: 1)
// 그룹 추가 서버 테스트
// groupAddWithAPI(groupRequest: GroupAddRequest(userId: "nada", groupName: "나다나다"))
// groupAddWithAPI(groupRequest: GroupAddRequest(userId: "nada", groupName: "대학교"))
// 그룹 수정 서버 테스트
// groupEditWithAPI(groupRequest: GroupEditRequest(groupId: 5, groupName: "수정나다"))
// 그룹 속 명함 추가 테스트
// cardAddInGroupWithAPI(cardRequest: CardAddInGroupRequest(cardId: "cardA", userId: "nada", groupId: 1))
// cardAddInGroupWithAPI(cardRequest: CardAddInGroupRequest(cardId: "cardC", userId: "nada", groupId: 18))
// 그룹 속 명함 조회 테스트
// cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada2", groupId: 3, offset: 0))
// cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada", groupId: 5, offset: 0))
// 명함 검색 테스트
// cardDetailFetchWithAPI(cardID: "cardA")

Expand Down Expand Up @@ -108,8 +111,9 @@ extension GroupViewController {
switch response {
case .success(let data):
if let group = data as? Groups {
// print(group)
// 그룹 리스트 조회 서버통신 성공했을때
self.serverGroups = group
self.groupCollectionView.reloadData()
self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada", groupId: group.groups[0].groupID, offset: 0))
}
case .requestErr(let message):
print("groupListFetchWithAPI - requestErr: \(message)")
Expand All @@ -126,11 +130,8 @@ extension GroupViewController {
func groupDeleteWithAPI(groupID: Int) {
GroupAPI.shared.groupDelete(groupID: groupID) { response in
switch response {
case .success(let data):
if let group = data as? Groups {
// print(group)
// 그룹 삭제 서버 통신 성공했을 떄
}
case .success:
print("groupDeleteWithAPI - success")
case .requestErr(let message):
print("groupDeleteWithAPI - requestErr: \(message)")
case .pathErr:
Expand All @@ -146,11 +147,8 @@ extension GroupViewController {
func groupAddWithAPI(groupRequest: GroupAddRequest) {
GroupAPI.shared.groupAdd(groupRequest: groupRequest) { response in
switch response {
case .success(let data):
if let group = data as? Groups {
// print(group)
// 그룹 추가 서버 통신 성공했을 떄
}
case .success:
print("groupAddWithAPI - success")
case .requestErr(let message):
print("groupAddWithAPI - requestErr: \(message)")
case .pathErr:
Expand All @@ -166,11 +164,8 @@ extension GroupViewController {
func groupEditWithAPI(groupRequest: GroupEditRequest) {
GroupAPI.shared.groupEdit(groupRequest: groupRequest) { response in
switch response {
case .success(let data):
if let group = data as? Groups {
// print(group)
// 그룹 추가 서버 통신 성공했을 떄
}
case .success:
print("groupEditWithAPI - success")
case .requestErr(let message):
print("groupEditWithAPI - requestErr: \(message)")
case .pathErr:
Expand All @@ -188,9 +183,8 @@ extension GroupViewController {
switch response {
case .success(let data):
if let cards = data as? CardsInGroupResponse {
// print(group)
// 그룹 추가 서버 통신 성공했을 떄
print(cards)
self.serverCards = cards
self.cardsCollectionView.reloadData()
}
case .requestErr(let message):
print("cardListInGroupWithAPI - requestErr: \(message)")
Expand All @@ -208,9 +202,26 @@ extension GroupViewController {
CardAPI.shared.cardDetailFetch(cardID: cardID) { response in
switch response {
case .success(let data):
if let card = data as? Card {
// print(card)
// 통신 성공
if let card = data as? CardClass {
guard let nextVC = UIStoryboard.init(name: Const.Storyboard.Name.cardDetail, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.cardDetailViewController) as? CardDetailViewController else { return }

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)
Comment on lines +208 to +223
Copy link
Member

Choose a reason for hiding this comment

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

card.card 뭔가 웃기네요 ㅎㅅㅎ

self.navigationController?.pushViewController(nextVC, animated: true)
}
case .requestErr(let message):
print("cardDetailFetchWithAPI - requestErr: \(message)")
Expand All @@ -223,6 +234,23 @@ 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 All @@ -235,9 +263,9 @@ extension GroupViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch collectionView {
case groupCollectionView:
return groups.count
return serverGroups?.groups.count ?? 0
case cardsCollectionView:
return 5
return serverCards?.cards.count ?? 0
default:
return 0
}
Expand All @@ -250,7 +278,8 @@ extension GroupViewController: UICollectionViewDataSource {
return UICollectionViewCell()
}

groupCell.groupName.text = groups[indexPath.row]
groupCell.groupName.text = serverGroups?.groups[indexPath.row].groupName

if indexPath.row == 0 {
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .init())
}
Expand All @@ -260,6 +289,16 @@ extension GroupViewController: UICollectionViewDataSource {
return UICollectionViewCell()
}

cardCell.backgroundImageView.updateServerImage(serverCards?.cards[indexPath.row].background ?? "")
cardCell.cardId = serverCards?.cards[indexPath.row].cardID
cardCell.titleLabel.text = serverCards?.cards[indexPath.row].title
cardCell.descriptionLabel.text = serverCards?.cards[indexPath.row].cardDescription
cardCell.userNameLabel.text = serverCards?.cards[indexPath.row].name
cardCell.birthLabel.text = serverCards?.cards[indexPath.row].birthDate
cardCell.mbtiLabel.text = serverCards?.cards[indexPath.row].mbti
cardCell.instagramIDLabel.text = serverCards?.cards[indexPath.row].instagram
cardCell.lineURLLabel.text = serverCards?.cards[indexPath.row].link

return cardCell
default:
return UICollectionViewCell()
Expand All @@ -269,11 +308,9 @@ extension GroupViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
switch collectionView {
case groupCollectionView:
print(indexPath.row)
cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada", groupId: serverGroups?.groups[indexPath.row].groupID ?? 0, offset: 0))
case cardsCollectionView:
guard let nextVC = UIStoryboard.init(name: Const.Storyboard.Name.cardDetail, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.cardDetailViewController) as? CardDetailViewController else { return }

navigationController?.pushViewController(nextVC, animated: true)
cardDetailFetchWithAPI(cardID: serverCards?.cards[indexPath.row].cardID ?? "")
default:
print(indexPath.row)
}
Expand All @@ -289,8 +326,8 @@ extension GroupViewController: UICollectionViewDelegateFlowLayout {

switch collectionView {
case groupCollectionView:
if groups[indexPath.row].count > 4 {
width = CGFloat(groups[indexPath.row].count) * 16
if serverGroups?.groups[indexPath.row].groupName.count ?? 0 > 4 {
width = CGFloat(serverGroups?.groups[indexPath.row].groupName.count ?? 0) * 16
} else {
width = 62
}
Expand All @@ -316,8 +353,6 @@ extension GroupViewController: UICollectionViewDelegateFlowLayout {
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
switch collectionView {
case groupCollectionView:
return 5
case cardsCollectionView:
return collectionView.frame.size.width * 15/327
default:
Expand All @@ -326,6 +361,8 @@ extension GroupViewController: UICollectionViewDelegateFlowLayout {
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
switch collectionView {
case groupCollectionView:
return 5
case cardsCollectionView:
return collectionView.frame.size.width * 15/327
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class FrontViewController: UIViewController {
isSoju: true,
isBoomuk: true,
isSauced: true,
oneTMI: "첫번째",
twoTMI: "두번째",
thirdTMI: "세번째세번째세번째"),
oneTmi: "첫번째",
twoTmi: "두번째",
threeTmi: "세번째세번째세번째"),
Card(cardID: "card",
background: "card",
title: "SOPT 명함",
Expand All @@ -42,9 +42,9 @@ class FrontViewController: UIViewController {
isSoju: true,
isBoomuk: true,
isSauced: true,
oneTMI: "첫번째",
twoTMI: "두번째",
thirdTMI: "세번째세번째세번째")]
oneTmi: "첫번째",
twoTmi: "두번째",
threeTmi: "세번째세번째세번째")]

// var cardDataList: [Card]? = []

Expand Down
Loading