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] #226 - 메인 무한스크롤 구현 및 data 모델 정리 #227

Merged
merged 5 commits into from
Dec 26, 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
4 changes: 0 additions & 4 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
39523E5B2701A48900536900 /* CardListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39523E592701A48900536900 /* CardListTableViewCell.swift */; };
39523E5C2701A48900536900 /* CardListTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 39523E5A2701A48900536900 /* CardListTableViewCell.xib */; };
39523E5F2701AA9000536900 /* CardListDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39523E5E2701AA9000536900 /* CardListDataModel.swift */; };
39584581273E951C009CC6B9 /* MainListRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39584580273E951C009CC6B9 /* MainListRequest.swift */; };
3958F239270FFBBF00B100B2 /* GroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3958F238270FFBBF00B100B2 /* GroupViewController.swift */; };
3958F23C270FFBD500B100B2 /* Group.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3958F23B270FFBD500B100B2 /* Group.storyboard */; };
3979709626FA0BE5003FB4F5 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3979709526FA0BE5003FB4F5 /* LoginViewController.swift */; };
Expand Down Expand Up @@ -175,7 +174,6 @@
39523E592701A48900536900 /* CardListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardListTableViewCell.swift; sourceTree = "<group>"; };
39523E5A2701A48900536900 /* CardListTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CardListTableViewCell.xib; sourceTree = "<group>"; };
39523E5E2701AA9000536900 /* CardListDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardListDataModel.swift; sourceTree = "<group>"; };
39584580273E951C009CC6B9 /* MainListRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainListRequest.swift; sourceTree = "<group>"; };
3958F238270FFBBF00B100B2 /* GroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupViewController.swift; sourceTree = "<group>"; };
3958F23B270FFBD500B100B2 /* Group.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Group.storyboard; sourceTree = "<group>"; };
3979709526FA0BE5003FB4F5 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -677,7 +675,6 @@
F871227727330A3800A24E74 /* CardCreationRequest.swift */,
3981148D273BEBB300E28630 /* CardListEditRequest.swift */,
3981148F273BEBCE00E28630 /* CardListRequest.swift */,
39584580273E951C009CC6B9 /* MainListRequest.swift */,
39288E11273F52B20072F403 /* CardListLookUpRequest.swift */,
);
path = Card;
Expand Down Expand Up @@ -1149,7 +1146,6 @@
F871227827330A3800A24E74 /* CardCreationRequest.swift in Sources */,
39D88B5F2745FB7E00A72164 /* MoreViewController.swift in Sources */,
F8FC43B326C020B90033E151 /* BackCardCreationDelegate.swift in Sources */,
39584581273E951C009CC6B9 /* MainListRequest.swift in Sources */,
39369944274A568900684420 /* GroupEditTableViewCell.swift in Sources */,
F8C83FBB272F9F370009DF0D /* NetworkResult.swift in Sources */,
39D2E130270B43DA00AD0889 /* UIFont+Extension.swift in Sources */,
Expand Down
12 changes: 6 additions & 6 deletions NADA-iOS-forRelease/Sources/Cells/CardCell/BackCardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ extension BackCardCell {
friedChickenImageView.image = cardData.isSauced == false ?
UIImage(named: "iconTasteOnFried") : UIImage(named: "iconTasteOffFried")

if !cardData.oneTmi.isEmpty {
firstTmiLabel.text = "" + cardData.oneTmi
if let oneTmi = cardData.oneTmi, !oneTmi.isEmpty {
firstTmiLabel.text = "" + oneTmi
} else {
firstTmiLabel.text = cardData.oneTmi
}

if !cardData.twoTmi.isEmpty {
secondTmiLabel.text = "" + cardData.twoTmi
if let twoTmi = cardData.twoTmi, !twoTmi.isEmpty {
secondTmiLabel.text = "" + twoTmi
} else {
secondTmiLabel.text = cardData.twoTmi
}

if !cardData.threeTmi.isEmpty {
thirdTmiLabel.text = "" + cardData.threeTmi
if let threeTmi = cardData.threeTmi, !threeTmi.isEmpty {
thirdTmiLabel.text = "" + threeTmi
} else {
thirdTmiLabel.text = cardData.threeTmi
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ extension FrontCardCell {
instagramIDLabel.text = cardData.instagram
linkURLLabel.text = cardData.link

if cardData.instagram.isEmpty {
if let instagram = cardData.instagram, instagram.isEmpty {
instagramImageView.isHidden = true
}
if cardData.link.isEmpty {
if let link = cardData.link, link.isEmpty {
linkURLImageView.isHidden = true
}

Expand Down
23 changes: 8 additions & 15 deletions NADA-iOS-forRelease/Sources/NetworkModel/Card/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,20 @@

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: String
let birthDate, mbti, instagram, link: String
let cardDescription: String
let cardID, background, title, name, birthDate, mbti: String
let instagram, link, cardDescription: String?
let isMincho, isSoju, isBoomuk, isSauced: Bool
let oneTmi, twoTmi, threeTmi: String
let oneTmi, twoTmi, threeTmi: String?

enum CodingKeys: String, CodingKey {
case cardID = "cardId"
case background, title, name, birthDate, mbti, instagram, link
case cardDescription = "description"
case isMincho, isSoju, isBoomuk, isSauced, oneTmi, twoTmi, threeTmi
}
}
// FIXME: - 메인에서 카드 정보 정적으로 생성하기 위한 주석
// TODO: - 쓰게 될줄 알았는데 안써서 일단 보류
// init(from decoder: Decoder) throws {
// let values = try decoder.container(keyedBy: CodingKeys.self)
// cardID = (try? values.decode(String.self, forKey: .cardID)) ?? ""
Expand All @@ -43,8 +36,8 @@ struct Card: Codable {
// isSoju = (try? values.decode(Bool.self, forKey: .isSoju)) ?? false
// isBoomuk = (try? values.decode(Bool.self, forKey: .isBoomuk)) ?? false
// isSauced = (try? values.decode(Bool.self, forKey: .isSauced)) ?? false
// oneTMI = (try? values.decode(String.self, forKey: .oneTMI))
// twoTMI = (try? values.decode(String.self, forKey: .twoTMI))
// thirdTMI = (try? values.decode(String.self, forKey: .thirdTMI))
// oneTmi = (try? values.decode(String.self, forKey: .oneTmi))
// twoTmi = (try? values.decode(String.self, forKey: .twoTmi))
// threeTmi = (try? values.decode(String.self, forKey: .threeTmi))
// }
//}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ import Foundation

struct CardsInGroupResponse: Codable {
let offset: Int
let cards: [Cards]
let cards: [FrontCard]

enum CodingKeys: String, CodingKey {
case offset
case cards
}

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
offset = (try? values.decode(Int.self, forKey: .offset)) ?? -1
cards = (try? values.decode([Cards].self, forKey: .cards)) ?? [Cards]()
}
// TODO: - 쓰게 될줄 알았는데 안써서 일단 보류
// init(from decoder: Decoder) throws {
// let values = try decoder.container(keyedBy: CodingKeys.self)
// offset = (try? values.decode(Int.self, forKey: .offset)) ?? -1
// cards = (try? values.decode([FrontCard].self, forKey: .cards)) ?? [FrontCard]()
// }
}

// MARK: - Cards
struct Cards: Codable {
struct FrontCard: Codable {
let cardID, background, title, name, birthDate, age, mbti: String
let instagram, linkName, link, cardDescription: String?

Expand All @@ -34,18 +35,19 @@ struct Cards: Codable {
case cardDescription = "description"
}

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
cardID = (try? values.decode(String.self, forKey: .cardID)) ?? ""
background = (try? values.decode(String.self, forKey: .background)) ?? ""
title = (try? values.decode(String.self, forKey: .title)) ?? ""
name = (try? values.decode(String.self, forKey: .name)) ?? ""
birthDate = (try? values.decode(String.self, forKey: .birthDate)) ?? ""
age = (try? values.decode(String.self, forKey: .age)) ?? ""
mbti = (try? values.decode(String.self, forKey: .mbti)) ?? ""
instagram = (try? values.decode(String.self, forKey: .instagram))
linkName = (try? values.decode(String.self, forKey: .linkName))
link = (try? values.decode(String.self, forKey: .link))
cardDescription = (try? values.decode(String.self, forKey: .cardDescription))
}
// TODO: - 쓰게 될줄 알았는데 안써서 일단 보류
// init(from decoder: Decoder) throws {
// let values = try decoder.container(keyedBy: CodingKeys.self)
// cardID = (try? values.decode(String.self, forKey: .cardID)) ?? ""
// background = (try? values.decode(String.self, forKey: .background)) ?? ""
// title = (try? values.decode(String.self, forKey: .title)) ?? ""
// name = (try? values.decode(String.self, forKey: .name)) ?? ""
// birthDate = (try? values.decode(String.self, forKey: .birthDate)) ?? ""
// age = (try? values.decode(String.self, forKey: .age)) ?? ""
// mbti = (try? values.decode(String.self, forKey: .mbti)) ?? ""
// instagram = (try? values.decode(String.self, forKey: .instagram))
// linkName = (try? values.decode(String.self, forKey: .linkName))
// link = (try? values.decode(String.self, forKey: .link))
// cardDescription = (try? values.decode(String.self, forKey: .cardDescription))
// }
}
22 changes: 12 additions & 10 deletions NADA-iOS-forRelease/Sources/NetworkModel/Group/Groups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ struct Groups: Codable {
enum CondingKeys: String, CodingKey {
case groups
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
groups = (try? values.decode([Group].self, forKey: .groups)) ?? [Group]()
}

// TODO: - 쓰게 될줄 알았는데 안써서 일단 보류
// init(from decoder: Decoder) throws {
// let values = try decoder.container(keyedBy: CodingKeys.self)
// groups = (try? values.decode([Group].self, forKey: .groups)) ?? [Group]()
// }
}

// MARK: - Group
Expand All @@ -31,10 +33,10 @@ struct Group: Codable {
case groupID = "groupId"
case groupName
}

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
groupID = (try? values.decode(Int.self, forKey: .groupID)) ?? -1
groupName = (try? values.decode(String.self, forKey: .groupName)) ?? ""
}
// TODO: - 쓰게 될줄 알았는데 안써서 일단 보류
// init(from decoder: Decoder) throws {
// let values = try decoder.container(keyedBy: CodingKeys.self)
// groupID = (try? values.decode(Int.self, forKey: .groupID)) ?? -1
// groupName = (try? values.decode(String.self, forKey: .groupName)) ?? ""
// }
}
10 changes: 5 additions & 5 deletions NADA-iOS-forRelease/Sources/NetworkModel/User/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ struct User: Codable {
enum CodingKeys: String, CodingKey {
case userID = "userId"
}

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
userID = (try? values.decode(String.self, forKey: .userID)) ?? ""
}
// TODO: - 쓰게 될줄 알았는데 안써서 일단 보류
// init(from decoder: Decoder) throws {
// let values = try decoder.container(keyedBy: CodingKeys.self)
// userID = (try? values.decode(String.self, forKey: .userID)) ?? ""
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class CardAPI {
private func judgeCardDetailFetchStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {

let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<CardClass>.self, from: data)
guard let decodedData = try? decoder.decode(GenericResponse<Card>.self, from: data)
else {
return .pathErr
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Moya
enum CardService {
case cardDetailFetch(cardID: String)
case cardCreation(request: CardCreationRequest, image: UIImage)
case cardListFetch(userID: String, isList: Bool?, offset: Int?)
case cardListFetch(userID: String, isList: Bool, offset: Int?)
case cardListEdit(request: CardListEditRequest)
case cardDelete(cardID: String)
}
Expand Down Expand Up @@ -101,9 +101,9 @@ extension CardService: TargetType {
return .uploadMultipart(multiPartData)
case .cardListFetch(let userID, let isList, let offset):
return .requestParameters(parameters: ["userId": userID,
"list": isList ?? false,
"offset": offset ?? ""
], encoding: URLEncoding.queryString)
"list": isList,
"offset": offset ?? ""],
encoding: URLEncoding.queryString)
case .cardListEdit(let requestModel):
return .requestJSONEncodable(requestModel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,11 @@ extension AddWithIdBottomSheetViewController {
CardAPI.shared.cardDetailFetch(cardID: cardID) { response in
switch response {
case .success(let data):
if let card = data as? CardClass {
if let card = data as? Card {
//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)
nextVC.cardDataModel = card
self.hideBottomSheetAndPresent(nextBottomSheet: nextVC, title: card.name, height: 574)
}
case .requestErr(let message):
print("cardDetailFetchWithAPI - requestErr: \(message)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController {
guard let cardDataModel = cardDataModel else { return UIImage() }
frontCard.initCell(UIImage(named: cardDataModel.background),
cardDataModel.title,
cardDataModel.cardDescription,
cardDataModel.cardDescription ?? "",
cardDataModel.name,
cardDataModel.birthDate,
cardDataModel.mbti,
cardDataModel.instagram ,
cardDataModel.link,
cardDataModel.instagram ?? "",
cardDataModel.link ?? "",
isShareable: isShareable)

let frontCardView = UIView(frame: CGRect(x: 0, y: 0, width: 327, height: 540))
Expand All @@ -153,9 +153,9 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController {
cardDataModel.isSoju,
cardDataModel.isBoomuk,
cardDataModel.isSauced,
cardDataModel.oneTmi,
cardDataModel.twoTmi,
cardDataModel.threeTmi,
cardDataModel.oneTmi ?? "",
cardDataModel.twoTmi ?? "",
cardDataModel.threeTmi ?? "",
isShareable: isShareable)

let backCardView = UIView(frame: CGRect(x: 0, y: 0, width: 327, height: 540))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,48 +222,6 @@ extension CardCreationViewController {
}
}

// MARK: - Network
extension CardCreationViewController {
// TODO: - card 서버통신. 위치변경.
// func cardDetailFetchWithAPI(cardID: String) {
// CardAPI.shared.cardDetailFetch(cardID: cardID) { response in
// switch response {
// case .success(let data):
// if let card = data as? Card {
// self.cardData = card
// }
// case .requestErr(let message):
// print("cardDetailFetchWithAPI - requestErr: \(message)")
// case .pathErr:
// print("cardDetailFetchWithAPI - pathErr")
// case .serverErr:
// print("cardDetailFetchWithAPI - serverErr")
// case .networkFail:
// print("cardDetailFetchWithAPI - networkFail")
// }
// }
// }

// TODO: - group 서버통신. 위치변경.
// func cardDeleteInGroupWithAPI(groupID: Int, cardID: String) {
// GroupAPI.shared.cardDeleteInGroup(groupID: groupID, cardID: cardID) { response in
// switch response {
// case .success:
// print("cardDeleteInGroupWithAPI - success")
// case .requestErr(let message):
// print("cardDeleteInGroupWithAPI - requestErr: \(message)")
// case .pathErr:
// print("cardDeleteInGroupWithAPI - pathErr")
// case .serverErr:
// print("cardDeleteInGroupWithAPI - serverErr")
// case .networkFail:
// print("cardDeleteInGroupWithAPI - networkFail")
// }
//
// }
// }
}

// MARK: - UICollectionViewDelegate
extension CardCreationViewController: UICollectionViewDelegate {
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
Expand Down
Loading