Skip to content

Commit

Permalink
[FEAT] #49 - Moya 서버통신 구축
Browse files Browse the repository at this point in the history
### Descriptions
Models -> App Model : 프로젝트 내에서 사용할 데이터 모델.
NetworkModel : 서버통신 시 사용할 데이터 모델. request body 에 넣을 데이터 모델도 여기서 정의. 네이밍 -> `~~Request` 라고 선언하기.
MoyaLoggerPlugin : log 확인할 수 있도록 인터페이스 생성해둠.
`~~API` : 서버통신을 위해 호출하는 함수. 네이밍 -> (httpMethod)(Service 에서 선언한 열거형) ex) getCardListPatch : 카드리스트 조회
`~~Service` : TargetType 채택해서 path, method, task, headers 설정.
NetworkResult : 서버통신 결과 열거형 정의.
GenericResponse : 제네릭을 사용한 공통적인 데이터 모델. data 역할만 NetworkModel 에서 선언해서 사용.

- pod update 했습니당
- Util 폴더에 Service 와 API 를 작성하는 예시 코드를 주석으로 달아뒀어요!

### Related Issue
close #49
  • Loading branch information
hyun99999 committed Nov 1, 2021
1 parent 2ef69ff commit af7286b
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 49 deletions.
116 changes: 102 additions & 14 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,24 @@
F84BAFB226FDB552004CA335 /* BackCardCreationCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F84BAFB026FDB552004CA335 /* BackCardCreationCollectionViewCell.xib */; };
F858079E2700354E00872484 /* BackgroundCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F858079C2700354E00872484 /* BackgroundCollectionViewCell.swift */; };
F858079F2700354E00872484 /* BackgroundCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F858079D2700354E00872484 /* BackgroundCollectionViewCell.xib */; };
F8C83FAE272F99940009DF0D /* MoyaLoggerPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FAD272F99940009DF0D /* MoyaLoggerPlugin.swift */; };
F8C83FB6272F9E380009DF0D /* UtilService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FB5272F9E380009DF0D /* UtilService.swift */; };
F8C83FB8272F9E3F0009DF0D /* UtilAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FB7272F9E3F0009DF0D /* UtilAPI.swift */; };
F8C83FBB272F9F370009DF0D /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FBA272F9F370009DF0D /* NetworkResult.swift */; };
F8C83FBD272F9F430009DF0D /* GenericResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FBC272F9F430009DF0D /* GenericResponse.swift */; };
F8C83FBF272FA0670009DF0D /* UserSevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FBE272FA0670009DF0D /* UserSevice.swift */; };
F8C83FC1272FA06E0009DF0D /* UserAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FC0272FA06E0009DF0D /* UserAPI.swift */; };
F8C83FC3272FA17B0009DF0D /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FC2272FA17B0009DF0D /* URL.swift */; };
F8C83FC5272FA2940009DF0D /* CardAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FC4272FA2940009DF0D /* CardAPI.swift */; };
F8C83FC7272FA2A20009DF0D /* CardService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FC6272FA2A20009DF0D /* CardService.swift */; };
F8C83FC9272FA3190009DF0D /* GroupAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FC8272FA3190009DF0D /* GroupAPI.swift */; };
F8C83FCB272FA32C0009DF0D /* GroupService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FCA272FA32C0009DF0D /* GroupService.swift */; };
F8F5D0AA270800FD00D99D2E /* Xib.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F5D0A9270800FD00D99D2E /* Xib.swift */; };
F8FC438626C01CDD0033E151 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC438526C01CDD0033E151 /* AppDelegate.swift */; };
F8FC438826C01CDD0033E151 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC438726C01CDD0033E151 /* SceneDelegate.swift */; };
F8FC438F26C01CDE0033E151 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F8FC438E26C01CDE0033E151 /* Assets.xcassets */; };
F8FC439226C01CDE0033E151 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F8FC439026C01CDE0033E151 /* LaunchScreen.storyboard */; };
F8FC43AD26C020940033E151 /* TempClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC43AC26C020940033E151 /* TempClass.swift */; };
F8FC43AF26C0209A0033E151 /* TempModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC43AE26C0209A0033E151 /* TempModel.swift */; };
F8FC43B126C020A70033E151 /* TempNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC43B026C020A70033E151 /* TempNetwork.swift */; };
F8FC43B326C020B90033E151 /* TempProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC43B226C020B90033E151 /* TempProtocols.swift */; };
F8FC43B526C020C10033E151 /* TempViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC43B426C020C10033E151 /* TempViews.swift */; };
F8FC43B826C0227D0033E151 /* Const.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC43B726C0227D0033E151 /* Const.swift */; };
Expand Down Expand Up @@ -104,6 +114,18 @@
F84BAFB026FDB552004CA335 /* BackCardCreationCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BackCardCreationCollectionViewCell.xib; sourceTree = "<group>"; };
F858079C2700354E00872484 /* BackgroundCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundCollectionViewCell.swift; sourceTree = "<group>"; };
F858079D2700354E00872484 /* BackgroundCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BackgroundCollectionViewCell.xib; sourceTree = "<group>"; };
F8C83FAD272F99940009DF0D /* MoyaLoggerPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoyaLoggerPlugin.swift; sourceTree = "<group>"; };
F8C83FB5272F9E380009DF0D /* UtilService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilService.swift; sourceTree = "<group>"; };
F8C83FB7272F9E3F0009DF0D /* UtilAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilAPI.swift; sourceTree = "<group>"; };
F8C83FBA272F9F370009DF0D /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
F8C83FBC272F9F430009DF0D /* GenericResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericResponse.swift; sourceTree = "<group>"; };
F8C83FBE272FA0670009DF0D /* UserSevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSevice.swift; sourceTree = "<group>"; };
F8C83FC0272FA06E0009DF0D /* UserAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserAPI.swift; sourceTree = "<group>"; };
F8C83FC2272FA17B0009DF0D /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = "<group>"; };
F8C83FC4272FA2940009DF0D /* CardAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardAPI.swift; sourceTree = "<group>"; };
F8C83FC6272FA2A20009DF0D /* CardService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardService.swift; sourceTree = "<group>"; };
F8C83FC8272FA3190009DF0D /* GroupAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupAPI.swift; sourceTree = "<group>"; };
F8C83FCA272FA32C0009DF0D /* GroupService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupService.swift; sourceTree = "<group>"; };
F8F5D0A9270800FD00D99D2E /* Xib.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Xib.swift; sourceTree = "<group>"; };
F8FC438226C01CDD0033E151 /* NADA-iOS-forRelease.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "NADA-iOS-forRelease.app"; sourceTree = BUILT_PRODUCTS_DIR; };
F8FC438526C01CDD0033E151 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -112,8 +134,6 @@
F8FC439126C01CDE0033E151 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
F8FC439326C01CDE0033E151 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F8FC43AC26C020940033E151 /* TempClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempClass.swift; sourceTree = "<group>"; };
F8FC43AE26C0209A0033E151 /* TempModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempModel.swift; sourceTree = "<group>"; };
F8FC43B026C020A70033E151 /* TempNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempNetwork.swift; sourceTree = "<group>"; };
F8FC43B226C020B90033E151 /* TempProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempProtocols.swift; sourceTree = "<group>"; };
F8FC43B426C020C10033E151 /* TempViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempViews.swift; sourceTree = "<group>"; };
F8FC43B726C0227D0033E151 /* Const.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Const.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -301,6 +321,59 @@
path = Background;
sourceTree = "<group>";
};
F8C83FAC272F998A0009DF0D /* Plugin */ = {
isa = PBXGroup;
children = (
F8C83FAD272F99940009DF0D /* MoyaLoggerPlugin.swift */,
);
path = Plugin;
sourceTree = "<group>";
};
F8C83FAF272F9C790009DF0D /* User */ = {
isa = PBXGroup;
children = (
F8C83FC0272FA06E0009DF0D /* UserAPI.swift */,
F8C83FBE272FA0670009DF0D /* UserSevice.swift */,
);
path = User;
sourceTree = "<group>";
};
F8C83FB0272F9CB10009DF0D /* Card */ = {
isa = PBXGroup;
children = (
F8C83FC4272FA2940009DF0D /* CardAPI.swift */,
F8C83FC6272FA2A20009DF0D /* CardService.swift */,
);
path = Card;
sourceTree = "<group>";
};
F8C83FB3272F9CF30009DF0D /* Group */ = {
isa = PBXGroup;
children = (
F8C83FC8272FA3190009DF0D /* GroupAPI.swift */,
F8C83FCA272FA32C0009DF0D /* GroupService.swift */,
);
path = Group;
sourceTree = "<group>";
};
F8C83FB4272F9E250009DF0D /* Util */ = {
isa = PBXGroup;
children = (
F8C83FB7272F9E3F0009DF0D /* UtilAPI.swift */,
F8C83FB5272F9E380009DF0D /* UtilService.swift */,
);
path = Util;
sourceTree = "<group>";
};
F8C83FB9272F9F030009DF0D /* NetworkModel */ = {
isa = PBXGroup;
children = (
F8C83FBA272F9F370009DF0D /* NetworkResult.swift */,
F8C83FBC272F9F430009DF0D /* GenericResponse.swift */,
);
path = NetworkModel;
sourceTree = "<group>";
};
F8FC437926C01CDD0033E151 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -348,8 +421,9 @@
F8FC438726C01CDD0033E151 /* SceneDelegate.swift */,
F8FC439B26C01EC30033E151 /* Cells */,
F8FC439C26C01EC90033E151 /* Classes */,
F8FC439D26C01EEC0033E151 /* Models */,
F8FC439E26C01EF70033E151 /* Network */,
F8FC439D26C01EEC0033E151 /* AppModel */,
F8C83FB9272F9F030009DF0D /* NetworkModel */,
F8FC439E26C01EF70033E151 /* NetworkService */,
F8FC439F26C01EFC0033E151 /* Protocols */,
F8FC43A026C01F040033E151 /* ViewControllers */,
F8FC43A126C01F1F0033E151 /* Views */,
Expand All @@ -375,21 +449,24 @@
path = Classes;
sourceTree = "<group>";
};
F8FC439D26C01EEC0033E151 /* Models */ = {
F8FC439D26C01EEC0033E151 /* AppModel */ = {
isa = PBXGroup;
children = (
39523E5D2701AA5700536900 /* CardList */,
F8FC43AE26C0209A0033E151 /* TempModel.swift */,
);
path = Models;
path = AppModel;
sourceTree = "<group>";
};
F8FC439E26C01EF70033E151 /* Network */ = {
F8FC439E26C01EF70033E151 /* NetworkService */ = {
isa = PBXGroup;
children = (
F8FC43B026C020A70033E151 /* TempNetwork.swift */,
F8C83FAC272F998A0009DF0D /* Plugin */,
F8C83FAF272F9C790009DF0D /* User */,
F8C83FB0272F9CB10009DF0D /* Card */,
F8C83FB3272F9CF30009DF0D /* Group */,
F8C83FB4272F9E250009DF0D /* Util */,
);
path = Network;
path = NetworkService;
sourceTree = "<group>";
};
F8FC439F26C01EFC0033E151 /* Protocols */ = {
Expand Down Expand Up @@ -444,6 +521,7 @@
F8FC43BB26C022A20033E151 /* Storyboard.swift */,
F8F5D0A9270800FD00D99D2E /* Xib.swift */,
F822E7A82709CEB60020452C /* Notification.swift */,
F8C83FC2272FA17B0009DF0D /* URL.swift */,
);
path = Constants;
sourceTree = "<group>";
Expand Down Expand Up @@ -608,26 +686,31 @@
buildActionMask = 2147483647;
files = (
F84BAF9D26FDB417004CA335 /* CardCreationViewController.swift in Sources */,
F8FC43B126C020A70033E151 /* TempNetwork.swift in Sources */,
F8C83FCB272FA32C0009DF0D /* GroupService.swift in Sources */,
F858079E2700354E00872484 /* BackgroundCollectionViewCell.swift in Sources */,
F8C83FBD272F9F430009DF0D /* GenericResponse.swift in Sources */,
39007F2C27080D8200E7143E /* UIViewController+Extension.swift in Sources */,
F8C83FB6272F9E380009DF0D /* UtilService.swift in Sources */,
3958F239270FFBBF00B100B2 /* GroupViewController.swift in Sources */,
3909242F26FA15E800236C51 /* UIView+Extension.swift in Sources */,
39523E09270184A700536900 /* CardListViewController.swift in Sources */,
399C55DF2711949D00845A54 /* CGPoint+Distance.swift in Sources */,
F83206AA26F61E3700D61711 /* FrontCardCell.swift in Sources */,
3979709626FA0BE5003FB4F5 /* LoginViewController.swift in Sources */,
39488E352706E17200BDC917 /* UIAlertController+Extension.swift in Sources */,
F8C83FBF272FA0670009DF0D /* UserSevice.swift in Sources */,
399C55DB2711927900845A54 /* CustomTabBarController.swift in Sources */,
39F5A3D0271461EA00191F94 /* BackCardCell.swift in Sources */,
39C1E88F270EC762006D2089 /* UIColor+Extension.swift in Sources */,
F8FC43AF26C0209A0033E151 /* TempModel.swift in Sources */,
F8C83FC9272FA3190009DF0D /* GroupAPI.swift in Sources */,
F8FC43B826C0227D0033E151 /* Const.swift in Sources */,
394F314C27081B3A00C83291 /* FrontViewController.swift in Sources */,
F8F5D0AA270800FD00D99D2E /* Xib.swift in Sources */,
F82FF8252702000000E57F8B /* RequiredFlavorCollectionViewCell.swift in Sources */,
F8C83FC7272FA2A20009DF0D /* CardService.swift in Sources */,
F8FC43B326C020B90033E151 /* TempProtocols.swift in Sources */,
F8FC43B526C020C10033E151 /* TempViews.swift in Sources */,
F8C83FBB272F9F370009DF0D /* NetworkResult.swift in Sources */,
39D2E130270B43DA00AD0889 /* UIFont+Extension.swift in Sources */,
39523E5B2701A48900536900 /* CardListTableViewCell.swift in Sources */,
399C55D72711921100845A54 /* CustomTabBarButton.swift in Sources */,
Expand All @@ -638,9 +721,14 @@
F84BAFB126FDB552004CA335 /* BackCardCreationCollectionViewCell.swift in Sources */,
F8FC43BC26C022A20033E151 /* Storyboard.swift in Sources */,
399C55DD271192D000845A54 /* CustomTabIndicatorView.swift in Sources */,
F8C83FC1272FA06E0009DF0D /* UserAPI.swift in Sources */,
F8C83FC3272FA17B0009DF0D /* URL.swift in Sources */,
F8C83FAE272F99940009DF0D /* MoyaLoggerPlugin.swift in Sources */,
F84BAFAD26FDB543004CA335 /* FrontCardCreationCollectionViewCell.swift in Sources */,
F822E7A92709CEB60020452C /* Notification.swift in Sources */,
F8C83FC5272FA2940009DF0D /* CardAPI.swift in Sources */,
F8FC438626C01CDD0033E151 /* AppDelegate.swift in Sources */,
F8C83FB8272F9E3F0009DF0D /* UtilAPI.swift in Sources */,
F8FC438826C01CDD0033E151 /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
14 changes: 14 additions & 0 deletions NADA-iOS-forRelease/Resouces/Constants/URL.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// GeneralAPI.swift
// NADA-iOS-forRelease
//
// Created by kimhyungyu on 2021/11/01.
//

import Foundation

extension Const {
struct URL {
static let baseURL = ""
}
}
8 changes: 0 additions & 8 deletions NADA-iOS-forRelease/Sources/Models/TempModel.swift

This file was deleted.

8 changes: 0 additions & 8 deletions NADA-iOS-forRelease/Sources/Network/TempNetwork.swift

This file was deleted.

27 changes: 27 additions & 0 deletions NADA-iOS-forRelease/Sources/NetworkModel/GenericResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// GenericResult.swift
// NADA-iOS-forRelease
//
// Created by kimhyungyu on 2021/11/01.
//

import Foundation

struct GenericResponse<T: Codable>: Codable {
var msg: String
var timestamp: String
var data: T?

enum CodingKeys: String, CodingKey {
case msg
case timestamp
case data
}

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
msg = (try? values.decode(String.self, forKey: .msg)) ?? ""
timestamp = (try? values.decode(String.self, forKey: .timestamp)) ?? ""
data = (try? values.decode(T.self, forKey: .data)) ?? nil
}
}
16 changes: 16 additions & 0 deletions NADA-iOS-forRelease/Sources/NetworkModel/NetworkResult.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// NetworkResult.swift
// NADA-iOS-forRelease
//
// Created by kimhyungyu on 2021/11/01.
//

import Foundation

enum NetworkResult<T> {
case success(T) // 서버 통신 성공
case requestErr(T) // 요청 에러 발생
case pathErr // 경로 에러
case serverErr // 서버의 내부적 에러
case networkFail // 네트워크 연결 실패
}
8 changes: 8 additions & 0 deletions NADA-iOS-forRelease/Sources/NetworkService/Card/CardAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// CardAPI.swift
// NADA-iOS-forRelease
//
// Created by kimhyungyu on 2021/11/01.
//

import Foundation
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// CardService.swift
// NADA-iOS-forRelease
//
// Created by kimhyungyu on 2021/11/01.
//

import Foundation
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// GroupAPI.swift
// NADA-iOS-forRelease
//
// Created by kimhyungyu on 2021/11/01.
//

import Foundation
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// GroupService.swift
// NADA-iOS-forRelease
//
// Created by kimhyungyu on 2021/11/01.
//

import Foundation
Loading

0 comments on commit af7286b

Please sign in to comment.