Skip to content

Commit

Permalink
[FEAT] TeamNADA#56 그룹 추가 서버통신
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwns33 committed Nov 5, 2021
1 parent f3c0dcb commit 103c7f5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
4 changes: 4 additions & 0 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
39F5A3D0271461EA00191F94 /* BackCardCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39F5A3CE271461EA00191F94 /* BackCardCell.swift */; };
39F5A3D1271461EA00191F94 /* BackCardCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 39F5A3CF271461EA00191F94 /* BackCardCell.xib */; };
777FF89B27359B7800BF69D3 /* Groups.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89A27359B7800BF69D3 /* Groups.swift */; };
777FF89D2735B16B00BF69D3 /* GroupAddRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89C2735B16B00BF69D3 /* GroupAddRequest.swift */; };
DBBB91E1639641F40C5B4416 /* Pods_NADA_iOS_forRelease.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A2183AE0E469153221624A0 /* Pods_NADA_iOS_forRelease.framework */; };
F822E7A92709CEB60020452C /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = F822E7A82709CEB60020452C /* Notification.swift */; };
F82FF81D2701EBCE00E57F8B /* CardCreation.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F82FF81C2701EBCE00E57F8B /* CardCreation.storyboard */; };
Expand Down Expand Up @@ -104,6 +105,7 @@
39F5A3CF271461EA00191F94 /* BackCardCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BackCardCell.xib; sourceTree = "<group>"; };
4A2183AE0E469153221624A0 /* Pods_NADA_iOS_forRelease.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NADA_iOS_forRelease.framework; sourceTree = BUILT_PRODUCTS_DIR; };
777FF89A27359B7800BF69D3 /* Groups.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Groups.swift; sourceTree = "<group>"; };
777FF89C2735B16B00BF69D3 /* GroupAddRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupAddRequest.swift; sourceTree = "<group>"; };
7F4EE1D042EC783FA8528743 /* Pods-NADA-iOS-forRelease.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NADA-iOS-forRelease.debug.xcconfig"; path = "Target Support Files/Pods-NADA-iOS-forRelease/Pods-NADA-iOS-forRelease.debug.xcconfig"; sourceTree = "<group>"; };
F822E7A82709CEB60020452C /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
F82FF81C2701EBCE00E57F8B /* CardCreation.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CardCreation.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -264,6 +266,7 @@
isa = PBXGroup;
children = (
777FF89A27359B7800BF69D3 /* Groups.swift */,
777FF89C2735B16B00BF69D3 /* GroupAddRequest.swift */,
);
path = Group;
sourceTree = "<group>";
Expand Down Expand Up @@ -732,6 +735,7 @@
F8C83FC9272FA3190009DF0D /* GroupAPI.swift in Sources */,
F8FC43B826C0227D0033E151 /* Const.swift in Sources */,
394F314C27081B3A00C83291 /* FrontViewController.swift in Sources */,
777FF89D2735B16B00BF69D3 /* GroupAddRequest.swift in Sources */,
F8F5D0AA270800FD00D99D2E /* Xib.swift in Sources */,
F82FF8252702000000E57F8B /* RequiredFlavorCollectionViewCell.swift in Sources */,
F8C83FC7272FA2A20009DF0D /* CardService.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// GroupAddRequest.swift
// NADA-iOS-forRelease
//
// Created by Yi Joon Choi on 2021/11/06.
//

import Foundation

struct GroupAddRequest: Codable {
var userId: String?
var groupName: String?
}
16 changes: 16 additions & 0 deletions NADA-iOS-forRelease/Sources/NetworkService/Group/GroupAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ public class GroupAPI {
}
}

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

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

case .failure(let err):
print(err)
}
}
}

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

let decoder = JSONDecoder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Moya
enum GroupService {
case groupListFetch(userID: String)
case groupDelete(groupID: Int)
case groupAdd(groupRequest: GroupAddRequest)
}

extension GroupService: TargetType {
Expand All @@ -25,6 +26,8 @@ extension GroupService: TargetType {
return "/groups"
case .groupDelete(let groupID):
return "/group/\(groupID)"
case .groupAdd:
return "/group"
}
}

Expand All @@ -34,6 +37,8 @@ extension GroupService: TargetType {
return .get
case .groupDelete:
return .delete
case .groupAdd:
return .post
}
}

Expand All @@ -47,6 +52,8 @@ extension GroupService: TargetType {
return .requestParameters(parameters: ["userId": userID], encoding: URLEncoding.queryString)
case .groupDelete:
return .requestPlain
case .groupAdd(let groupRequest):
return .requestJSONEncodable(groupRequest)
}
}

Expand All @@ -56,6 +63,8 @@ extension GroupService: TargetType {
return ["Content-Type": "application/json"]
case .groupDelete:
return ["Content-Type": "application/json"]
case .groupAdd:
return ["Content-Type": "application/json"]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class GroupViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

//그룹 리스트 조회 서버 테스트
// 그룹 리스트 조회 서버 테스트
getGroupListFetchWithAPI(userID: "nada")
//그룹 삭제 서버 테스트
// 그룹 삭제 서버 테스트
deleteGroupWithAPI(groupID: 1)
// 그룹 추가 서버 테스트
postGroupAddWithAPI(groupRequest: GroupAddRequest(userId: "nada", groupName: "나다나다"))
}

}
Expand All @@ -28,7 +30,8 @@ extension GroupViewController {
switch response {
case .success(let data):
if let group = data as? Groups {
print(group)
// print(group)
// 그룹 리스트 조회 서버통신 성공했을때
}
case .requestErr(let message):
print("getGroupListFetchWithAPI - requestErr", message)
Expand All @@ -43,20 +46,41 @@ extension GroupViewController {
}

func deleteGroupWithAPI(groupID: Int) {
GroupAPI.shared.deleteGroup(groupID: groupID) { response in
GroupAPI.shared.deleteGroup(groupID: groupID) { response in
switch response {
case .success(let data):
if let group = data as? Groups {
print(group)
// print(group)
// 그룹 삭제 서버 통신 성공했을 떄
}
case .requestErr(let message):
print("getGroupListFetchWithAPI - requestErr", message)
print("deleteGroupWithAPI - requestErr", message)
case .pathErr:
print("getGroupListFetchWithAPI - pathErr")
print("deleteGroupWithAPI - pathErr")
case .serverErr:
print("getGroupListFetchWithAPI - serverErr")
print("deleteGroupWithAPI - serverErr")
case .networkFail:
print("getGroupListFetchWithAPI - networkFail")
print("deleteGroupWithAPI - networkFail")
}
}
}

func postGroupAddWithAPI(groupRequest: GroupAddRequest) {
GroupAPI.shared.postGroupAdd(groupRequest: groupRequest) { response in
switch response {
case .success(let data):
if let group = data as? Groups {
// print(group)
// 그룹 추가 서버 통신 성공했을 떄
}
case .requestErr(let message):
print("postGroupAddWithAPI - requestErr", message)
case .pathErr:
print("postGroupAddWithAPI - pathErr")
case .serverErr:
print("postGroupAddWithAPI - serverErr")
case .networkFail:
print("postGroupAddWithAPI - networkFail")
}
}
}
Expand Down

0 comments on commit 103c7f5

Please sign in to comment.