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: 명함 그룹 조회 API 연결 #422 #432

Merged
merged 7 commits into from
Apr 15, 2023
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 @@ -21,8 +21,8 @@ class CardInGroupCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var instagramIcon: UIImageView!
@IBOutlet weak var urlIcon: UIImageView!
var groupId: Int?
var cardId: String?
var groupID: Int?
var cardUUID: String?

override func awakeFromNib() {
super.awakeFromNib()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

struct CardListInGroupRequest: Codable {
var userId: String
var groupId: Int
var offset: Int
var cardGroupId: Int
var pageNo: Int
var pageSize: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ struct CardsInGroupResponse: Codable {

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

enum CodingKeys: String, CodingKey {
case cardID = "cardId"
case background, title, name, birthDate, mbti, instagram, link
case cardDescription = "description"
}
let birth: String
let cardID: Int
let cardImage, cardName, cardType, cardUUID: String
let departmentName, instagram, mailAddress, mbti: String
let phoneNumber, tmi, twitter, urls: String
let userName: String

enum CodingKeys: String, CodingKey {
case birth
case cardID = "cardId"
case cardImage, cardName, cardType
case cardUUID = "cardUuid"
case departmentName, instagram, mailAddress, mbti, phoneNumber, tmi, twitter, urls, userName
}
}
9 changes: 2 additions & 7 deletions NADA-iOS-forRelease/Sources/NetworkModel/Group/Groups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ struct Groups: Codable {
// MARK: - Group

struct Group: Codable {
var groupID: Int
var groupName: String

enum CodingKeys: String, CodingKey {
case groupID = "groupId"
case groupName
}
var cardGroupId: Int
Copy link
Member

Choose a reason for hiding this comment

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

cardGroupID 로 사용부탁드려요 😤

Copy link
Member Author

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ반영했씁니다
image

var cardGroupName: String
}
25 changes: 12 additions & 13 deletions NADA-iOS-forRelease/Sources/NetworkService/Group/GroupAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GroupAPI {
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self)
completion(networkResult)

case .failure(let err):
Expand All @@ -38,7 +38,7 @@ public class GroupAPI {
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self)
completion(networkResult)

case .failure(let err):
Expand All @@ -48,13 +48,13 @@ public class GroupAPI {
}

func groupListFetch(userID: String, completion: @escaping (NetworkResult<Any>) -> Void) {
groupProvider.request(.groupListFetch(userID: userID)) { (result) in
groupProvider.request(.groupListFetch) { (result) in
switch result {
case .success(let response):
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeGroupListFetchStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data: data, type: [Group].self)
completion(networkResult)

case .failure(let err):
Expand All @@ -70,7 +70,7 @@ public class GroupAPI {
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self)
completion(networkResult)

case .failure(let err):
Expand All @@ -86,7 +86,7 @@ public class GroupAPI {
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self)
completion(networkResult)

case .failure(let err):
Expand All @@ -102,7 +102,7 @@ public class GroupAPI {
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self)
completion(networkResult)

case .failure(let err):
Expand All @@ -118,7 +118,7 @@ public class GroupAPI {
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self)
completion(networkResult)

case .failure(let err):
Expand All @@ -134,7 +134,7 @@ public class GroupAPI {
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeCardListFetchInGroupStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data: data, type: [Card].self)
completion(networkResult)

case .failure(let err):
Expand All @@ -150,7 +150,7 @@ public class GroupAPI {
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeStatus(by: statusCode, data)
let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self)
completion(networkResult)

case .failure(let err):
Expand Down Expand Up @@ -201,10 +201,9 @@ public class GroupAPI {
}
}

private func judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {

private func judgeStatus<T: Codable>(by statusCode: Int, data: Data, type: T.Type) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<String>.self, from: data)
guard let decodedData = try? decoder.decode(GenericResponse<T>.self, from: data)
else { return .pathErr }

switch statusCode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import Moya

enum GroupService {
case groupListFetch(userID: String)
case groupListFetch
case groupDelete(groupID: Int, defaultGroupId: Int)
case groupAdd(groupRequest: GroupAddRequest)
case groupEdit(groupRequest: GroupEditRequest)
Expand Down Expand Up @@ -37,15 +37,15 @@ extension GroupService: TargetType {
var path: String {
switch self {
case .groupListFetch, .groupReset:
return "/groups"
return "/card-group/list"
case .groupDelete(let groupID, _):
return "/group/\(groupID)"
case .groupAdd, .groupEdit:
return "/group"
case .cardAddInGroup, .changeCardGroup:
return "/groups/card"
case .cardListFetchInGroup:
return "/groups/cards"
case .cardListFetchInGroup(let cardListInGroupRequest):
return "/card-group/\(cardListInGroupRequest.cardGroupId)/cards"
case .cardDeleteInGroup(let groupID, let cardID):
return "/group/\(groupID)/\(cardID)"
}
Expand All @@ -70,9 +70,8 @@ extension GroupService: TargetType {

var task: Task {
switch self {
case .groupListFetch(let userID):
return .requestParameters(parameters: ["userId": userID],
encoding: URLEncoding.queryString)
case .groupListFetch:
return .requestPlain
case .cardDeleteInGroup, .groupReset:
return .requestPlain
case .groupDelete(_, let defaultGroupId):
Expand All @@ -85,9 +84,8 @@ extension GroupService: TargetType {
case .cardAddInGroup(let cardRequest):
return .requestJSONEncodable(cardRequest)
case .cardListFetchInGroup(let cardListInGroupRequest):
return .requestParameters(parameters: ["userId": cardListInGroupRequest.userId,
"groupId": cardListInGroupRequest.groupId,
"offset": cardListInGroupRequest.offset], encoding: URLEncoding.queryString)
return .requestParameters(parameters: ["pageNo": cardListInGroupRequest.pageNo,
"pageSize": cardListInGroupRequest.pageSize], encoding: URLEncoding.queryString)
case .changeCardGroup(let requestModel):
return .requestJSONEncodable(requestModel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class GroupNameEditBottomSheetViewController: CommonBottomSheetViewController, U
extension GroupNameEditBottomSheetViewController {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
groupEditWithAPI(groupRequest: GroupEditRequest(groupId: nowGroup?.groupID ?? 0, groupName: addGroupTextField.text ?? ""))
groupEditWithAPI(groupRequest: GroupEditRequest(groupId: nowGroup?.cardGroupId ?? 0, groupName: addGroupTextField.text ?? ""))
nowHideBottomSheetAndGoBack()

return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SelectGroupBottomSheetViewController: CommonBottomSheetViewController {
private func setupUI() {
view.addSubview(groupPicker)
view.addSubview(doneButton)
selectedGroup = serverGroups?.groups[0].groupID ?? 0
selectedGroup = serverGroups?.groups[0].cardGroupId ?? 0
groupPicker.delegate = self
groupPicker.dataSource = self
setupLayout()
Expand Down Expand Up @@ -113,16 +113,16 @@ extension SelectGroupBottomSheetViewController: UIPickerViewDelegate, UIPickerVi
label.textAlignment = .center

if pickerView.selectedRow(inComponent: component) == row {
label.attributedText = NSAttributedString(string: serverGroups?.groups[row].groupName ?? "", attributes: [NSAttributedString.Key.font: UIFont.textBold01, NSAttributedString.Key.foregroundColor: UIColor.mainColorNadaMain])
label.attributedText = NSAttributedString(string: serverGroups?.groups[row].cardGroupName ?? "", attributes: [NSAttributedString.Key.font: UIFont.textBold01, NSAttributedString.Key.foregroundColor: UIColor.mainColorNadaMain])
} else {
label.attributedText = NSAttributedString(string: serverGroups?.groups[row].groupName ?? "", attributes: [NSAttributedString.Key.font: UIFont.textRegular03, NSAttributedString.Key.foregroundColor: UIColor.quaternary])
label.attributedText = NSAttributedString(string: serverGroups?.groups[row].cardGroupName ?? "", attributes: [NSAttributedString.Key.font: UIFont.textRegular03, NSAttributedString.Key.foregroundColor: UIColor.quaternary])
}

return label
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
selectedGroup = serverGroups?.groups[row].groupID ?? 0
selectedGroup = serverGroups?.groups[row].cardGroupId ?? 0
selectedGroupIndex = row
pickerView.reloadAllComponents()
}
Expand Down
Loading