diff --git a/NADA-iOS-forRelease.xcodeproj/project.pbxproj b/NADA-iOS-forRelease.xcodeproj/project.pbxproj index 8136977c..f82e8912 100644 --- a/NADA-iOS-forRelease.xcodeproj/project.pbxproj +++ b/NADA-iOS-forRelease.xcodeproj/project.pbxproj @@ -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 */; }; @@ -104,6 +114,18 @@ F84BAFB026FDB552004CA335 /* BackCardCreationCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BackCardCreationCollectionViewCell.xib; sourceTree = ""; }; F858079C2700354E00872484 /* BackgroundCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundCollectionViewCell.swift; sourceTree = ""; }; F858079D2700354E00872484 /* BackgroundCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BackgroundCollectionViewCell.xib; sourceTree = ""; }; + F8C83FAD272F99940009DF0D /* MoyaLoggerPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoyaLoggerPlugin.swift; sourceTree = ""; }; + F8C83FB5272F9E380009DF0D /* UtilService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilService.swift; sourceTree = ""; }; + F8C83FB7272F9E3F0009DF0D /* UtilAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilAPI.swift; sourceTree = ""; }; + F8C83FBA272F9F370009DF0D /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = ""; }; + F8C83FBC272F9F430009DF0D /* GenericResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericResponse.swift; sourceTree = ""; }; + F8C83FBE272FA0670009DF0D /* UserSevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSevice.swift; sourceTree = ""; }; + F8C83FC0272FA06E0009DF0D /* UserAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserAPI.swift; sourceTree = ""; }; + F8C83FC2272FA17B0009DF0D /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = ""; }; + F8C83FC4272FA2940009DF0D /* CardAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardAPI.swift; sourceTree = ""; }; + F8C83FC6272FA2A20009DF0D /* CardService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardService.swift; sourceTree = ""; }; + F8C83FC8272FA3190009DF0D /* GroupAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupAPI.swift; sourceTree = ""; }; + F8C83FCA272FA32C0009DF0D /* GroupService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupService.swift; sourceTree = ""; }; F8F5D0A9270800FD00D99D2E /* Xib.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Xib.swift; sourceTree = ""; }; 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 = ""; }; @@ -112,8 +134,6 @@ F8FC439126C01CDE0033E151 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; F8FC439326C01CDE0033E151 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; F8FC43AC26C020940033E151 /* TempClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempClass.swift; sourceTree = ""; }; - F8FC43AE26C0209A0033E151 /* TempModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempModel.swift; sourceTree = ""; }; - F8FC43B026C020A70033E151 /* TempNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempNetwork.swift; sourceTree = ""; }; F8FC43B226C020B90033E151 /* TempProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempProtocols.swift; sourceTree = ""; }; F8FC43B426C020C10033E151 /* TempViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempViews.swift; sourceTree = ""; }; F8FC43B726C0227D0033E151 /* Const.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Const.swift; sourceTree = ""; }; @@ -301,6 +321,59 @@ path = Background; sourceTree = ""; }; + F8C83FAC272F998A0009DF0D /* Plugin */ = { + isa = PBXGroup; + children = ( + F8C83FAD272F99940009DF0D /* MoyaLoggerPlugin.swift */, + ); + path = Plugin; + sourceTree = ""; + }; + F8C83FAF272F9C790009DF0D /* User */ = { + isa = PBXGroup; + children = ( + F8C83FC0272FA06E0009DF0D /* UserAPI.swift */, + F8C83FBE272FA0670009DF0D /* UserSevice.swift */, + ); + path = User; + sourceTree = ""; + }; + F8C83FB0272F9CB10009DF0D /* Card */ = { + isa = PBXGroup; + children = ( + F8C83FC4272FA2940009DF0D /* CardAPI.swift */, + F8C83FC6272FA2A20009DF0D /* CardService.swift */, + ); + path = Card; + sourceTree = ""; + }; + F8C83FB3272F9CF30009DF0D /* Group */ = { + isa = PBXGroup; + children = ( + F8C83FC8272FA3190009DF0D /* GroupAPI.swift */, + F8C83FCA272FA32C0009DF0D /* GroupService.swift */, + ); + path = Group; + sourceTree = ""; + }; + F8C83FB4272F9E250009DF0D /* Util */ = { + isa = PBXGroup; + children = ( + F8C83FB7272F9E3F0009DF0D /* UtilAPI.swift */, + F8C83FB5272F9E380009DF0D /* UtilService.swift */, + ); + path = Util; + sourceTree = ""; + }; + F8C83FB9272F9F030009DF0D /* NetworkModel */ = { + isa = PBXGroup; + children = ( + F8C83FBA272F9F370009DF0D /* NetworkResult.swift */, + F8C83FBC272F9F430009DF0D /* GenericResponse.swift */, + ); + path = NetworkModel; + sourceTree = ""; + }; F8FC437926C01CDD0033E151 = { isa = PBXGroup; children = ( @@ -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 */, @@ -375,21 +449,24 @@ path = Classes; sourceTree = ""; }; - F8FC439D26C01EEC0033E151 /* Models */ = { + F8FC439D26C01EEC0033E151 /* AppModel */ = { isa = PBXGroup; children = ( 39523E5D2701AA5700536900 /* CardList */, - F8FC43AE26C0209A0033E151 /* TempModel.swift */, ); - path = Models; + path = AppModel; sourceTree = ""; }; - 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 = ""; }; F8FC439F26C01EFC0033E151 /* Protocols */ = { @@ -444,6 +521,7 @@ F8FC43BB26C022A20033E151 /* Storyboard.swift */, F8F5D0A9270800FD00D99D2E /* Xib.swift */, F822E7A82709CEB60020452C /* Notification.swift */, + F8C83FC2272FA17B0009DF0D /* URL.swift */, ); path = Constants; sourceTree = ""; @@ -608,9 +686,11 @@ 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 */, @@ -618,16 +698,19 @@ 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 */, @@ -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; diff --git a/NADA-iOS-forRelease/Resouces/Constants/URL.swift b/NADA-iOS-forRelease/Resouces/Constants/URL.swift new file mode 100644 index 00000000..9750da44 --- /dev/null +++ b/NADA-iOS-forRelease/Resouces/Constants/URL.swift @@ -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 = "" + } +} diff --git a/NADA-iOS-forRelease/Sources/Models/CardList/CardListDataModel.swift b/NADA-iOS-forRelease/Sources/AppModel/CardList/CardListDataModel.swift similarity index 100% rename from NADA-iOS-forRelease/Sources/Models/CardList/CardListDataModel.swift rename to NADA-iOS-forRelease/Sources/AppModel/CardList/CardListDataModel.swift diff --git a/NADA-iOS-forRelease/Sources/Models/TempModel.swift b/NADA-iOS-forRelease/Sources/Models/TempModel.swift deleted file mode 100644 index e2be5f33..00000000 --- a/NADA-iOS-forRelease/Sources/Models/TempModel.swift +++ /dev/null @@ -1,8 +0,0 @@ -// -// TempModel.swift -// NADA-iOS-forRelease -// -// Created by kimhyungyu on 2021/08/08. -// - -import Foundation diff --git a/NADA-iOS-forRelease/Sources/Network/TempNetwork.swift b/NADA-iOS-forRelease/Sources/Network/TempNetwork.swift deleted file mode 100644 index c5b22346..00000000 --- a/NADA-iOS-forRelease/Sources/Network/TempNetwork.swift +++ /dev/null @@ -1,8 +0,0 @@ -// -// TempNetwork.swift -// NADA-iOS-forRelease -// -// Created by kimhyungyu on 2021/08/08. -// - -import Foundation diff --git a/NADA-iOS-forRelease/Sources/NetworkModel/GenericResponse.swift b/NADA-iOS-forRelease/Sources/NetworkModel/GenericResponse.swift new file mode 100644 index 00000000..ff86c1a2 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkModel/GenericResponse.swift @@ -0,0 +1,27 @@ +// +// GenericResult.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation + +struct GenericResponse: 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 + } +} diff --git a/NADA-iOS-forRelease/Sources/NetworkModel/NetworkResult.swift b/NADA-iOS-forRelease/Sources/NetworkModel/NetworkResult.swift new file mode 100644 index 00000000..9c3a7a6d --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkModel/NetworkResult.swift @@ -0,0 +1,16 @@ +// +// NetworkResult.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation + +enum NetworkResult { + case success(T) // 서버 통신 성공 + case requestErr(T) // 요청 에러 발생 + case pathErr // 경로 에러 + case serverErr // 서버의 내부적 에러 + case networkFail // 네트워크 연결 실패 +} diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Card/CardAPI.swift b/NADA-iOS-forRelease/Sources/NetworkService/Card/CardAPI.swift new file mode 100644 index 00000000..9ead2a4a --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Card/CardAPI.swift @@ -0,0 +1,8 @@ +// +// CardAPI.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Card/CardService.swift b/NADA-iOS-forRelease/Sources/NetworkService/Card/CardService.swift new file mode 100644 index 00000000..aac2c9e1 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Card/CardService.swift @@ -0,0 +1,8 @@ +// +// CardService.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupAPI.swift b/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupAPI.swift new file mode 100644 index 00000000..11200069 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupAPI.swift @@ -0,0 +1,8 @@ +// +// GroupAPI.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupService.swift b/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupService.swift new file mode 100644 index 00000000..c25fa6c6 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupService.swift @@ -0,0 +1,8 @@ +// +// GroupService.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Plugin/MoyaLoggerPlugin.swift b/NADA-iOS-forRelease/Sources/NetworkService/Plugin/MoyaLoggerPlugin.swift new file mode 100644 index 00000000..3593a949 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Plugin/MoyaLoggerPlugin.swift @@ -0,0 +1,71 @@ +// +// File.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation +import Moya + +final class MoyaLoggerPlugin: PluginType { + + // Request를 보낼 때 호출 + func willSend(_ request: RequestType, target: TargetType) { + guard let httpRequest = request.request else { + print("--> 유효하지 않은 요청") + return + } + let url = httpRequest.description + let method = httpRequest.httpMethod ?? "unknown method" + var log = "----------------------------------------------------\n[\(method)] \(url)\n----------------------------------------------------\n" + log.append("API: \(target)\n") + if let headers = httpRequest.allHTTPHeaderFields, !headers.isEmpty { + log.append("header: \(headers)\n") + } + if let body = httpRequest.httpBody, let bodyString = String(bytes: body, encoding: String.Encoding.utf8) { + log.append("\(bodyString)\n") + } + log.append("------------------- END \(method) --------------------------") + print(log) + } + + // Response가 왔을 때 + func didReceive(_ result: Result, target: TargetType) { + switch result { + case let .success(response): + onSuceed(response, target: target, isFromError: false) + case let .failure(error): + onFail(error, target: target) + } + } + + func onSuceed(_ response: Response, target: TargetType, isFromError: Bool) { + let request = response.request + let url = request?.url?.absoluteString ?? "nil" + let statusCode = response.statusCode + var log = "------------------- 네트워크 통신 성공(isFromError: \(isFromError) -------------------" + log.append("\n[\(statusCode)] \(url)\n----------------------------------------------------\n") + log.append("API: \(target)\n") + response.response?.allHeaderFields.forEach { + log.append("\($0): \($1)\n") + } + if let reString = String(bytes: response.data, encoding: String.Encoding.utf8) { + log.append("\(reString)\n") + } + log.append("------------------- END HTTP (\(response.data.count)-byte body) -------------------") + print(log) + } + + func onFail(_ error: MoyaError, target: TargetType) { + if let response = error.response { + onSuceed(response, target: target, isFromError: true) + return + } + var log = "네트워크 오류" + log.append("<-- \(error.errorCode) \(target)\n") + log.append("\(error.failureReason ?? error.errorDescription ?? "unknown error")\n") + log.append("<-- END HTTP") + print(log) + } +} diff --git a/NADA-iOS-forRelease/Sources/NetworkService/User/UserAPI.swift b/NADA-iOS-forRelease/Sources/NetworkService/User/UserAPI.swift new file mode 100644 index 00000000..1ffe5ec3 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/User/UserAPI.swift @@ -0,0 +1,8 @@ +// +// UserAPI.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation diff --git a/NADA-iOS-forRelease/Sources/NetworkService/User/UserSevice.swift b/NADA-iOS-forRelease/Sources/NetworkService/User/UserSevice.swift new file mode 100644 index 00000000..9e333f1d --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/User/UserSevice.swift @@ -0,0 +1,8 @@ +// +// UserSevice.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Util/UtilAPI.swift b/NADA-iOS-forRelease/Sources/NetworkService/Util/UtilAPI.swift new file mode 100644 index 00000000..9b423906 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Util/UtilAPI.swift @@ -0,0 +1,101 @@ +// +// UtilAPI.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation +import Moya + +//public class UtilAPI { +// +// static let shared = UtilAPI() +// var popoProvider = MoyaProvider(plugins: [MoyaLoggerPlugin()]) +// +// public init() { } +// +// func getTodayFetch(popoID: Int, dayID: Int, completion: @escaping (NetworkResult) -> Void) { +// popoProvider.request(.todayFetch(popoID: popoID, dayID: dayID)) { (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) +// } +// } +// } +// +// func patchTodayPatch(popoID: Int, dayID: Int, contentsID: Int, contents: String, completion: @escaping (NetworkResult) -> Void) { +// popoProvider.request(.todayPatch(popoID: popoID, dayID: dayID, contentsID: contentsID, contents: contents)) { (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) +// } +// } +// } +// +// func postNewPopo(popoId: Int, contents: NewPopo, image: UIImage, completion: @escaping (NetworkResult) -> Void) { +// popoProvider.request(.createTodayPopo(popoId: popoId, contents: contents, image: image)) { (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) +// } +// } +// } +// +// func patchTodayImage(popoId: Int, dayId: Int, image: UIImage, completion: @escaping (NetworkResult) -> Void) { +// popoProvider.request(.patchTodayImage(popoId: popoId, dayId: dayId, image: image)) { (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 { +// +// let decoder = JSONDecoder() +// guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) +// else { +// return .pathErr +// } +// +// switch statusCode { +// case 200: +// return .success(decodedData.data) +// case 400..<500: +// return .requestErr(decodedData.message) +// case 500: +// return .serverErr +// default: +// return .networkFail +// } +// } +//} diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Util/UtilService.swift b/NADA-iOS-forRelease/Sources/NetworkService/Util/UtilService.swift new file mode 100644 index 00000000..2ab40a34 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Util/UtilService.swift @@ -0,0 +1,112 @@ +// +// UtilService.swift +// NADA-iOS-forRelease +// +// Created by kimhyungyu on 2021/11/01. +// + +import Foundation +import Moya + +//enum UtilService { +// case todayFetch(popoID: Int, dayID: Int) +// case todayPatch(popoID: Int, dayID: Int, contentsID: Int, contents: String) +// +// case createTodayPopo(popoId: Int, contents: NewPopo, image: UIImage) +// case patchTodayImage(popoId: Int, dayId: Int, image: UIImage) +//} +// +//extension UtilService: TargetType { +// var baseURL: URL { +// return URL(string: Const.URL.baseURL)! +// } +// +// var path: String { +// switch self { +// case .todayFetch(let popoID, let dayID): +// return "/\(popoID)/tracker/\(dayID)" +// case .todayPatch(let popoID, let dayID, let contentsID, _): +// return "/\(popoID)/tracker/\(dayID)/contents/\(contentsID)" +// case .createTodayPopo(let popoId, _, _): +// return "/\(popoId)/tracker" +// case .patchTodayImage(let popoId, let dayId, _): +// return "/\(popoId)/tracker/\(dayId)/image" +// } +// } +// +// var method: Moya.Method { +// switch self { +// case .todayFetch: +// return .get +// case .todayPatch: +// return .patch +// case .createTodayPopo(_, _, _): +// return .post +// case .patchTodayImage(_, _, _): +// return .patch +// } +// } +// +// var task: Task { +// switch self { +// case .todayFetch: +// return .requestPlain +// case .todayPatch(_, _, let contentsID, let contents): +// return .requestParameters(parameters: [ +// "id": contentsID, +// "contents": contents +// ], encoding: JSONEncoding.default) +// +// case .createTodayPopo(let popoId, let contents, let image): +// +// var options: [[String: Any]] = [] +// +// var multiPartFormData: [Moya.MultipartFormData] = [] +// +// let idJsondata = "\(popoId)".data(using: String.Encoding.utf8) ?? Data() +// multiPartFormData.append(MultipartFormData(provider: .data(idJsondata), name: "popoId")) +// +// let dateJsondata = contents.date.data(using: String.Encoding.utf8) ?? Data() +// multiPartFormData.append(MultipartFormData(provider: .data(dateJsondata), name: "date")) +// +// for (idx, option) in contents.options.enumerated() { +// +// let optionIdJsondata = "\(option.optionId)".data(using: String.Encoding.utf8) ?? Data() +// multiPartFormData.append(MultipartFormData(provider: .data(optionIdJsondata), name: "options[\(idx)].optionId")) +// +// let optionContentsJsondata = "\(option.contents)".data(using: String.Encoding.utf8) ?? Data() +// multiPartFormData.append(MultipartFormData(provider: .data(optionContentsJsondata), name: "options[\(idx)].contents")) +// +// } +// +// let imageData = image.pngData() +// let imgData = MultipartFormData(provider: .data(imageData!), name: "image", fileName: "image", mimeType: "image/png") +// multiPartFormData.append(imgData) +// +// return .uploadMultipart(multiPartFormData) +// case .patchTodayImage(_, _, let image): +// let imageData = image.pngData() +// let imgData = MultipartFormData(provider: .data(imageData!), name: "image", fileName: "image", mimeType: "image/png") +// return .uploadMultipart([imgData]) +// } +// } +// +// var headers: [String: String]? { +// switch self { +// case .todayFetch: +// return .none +// case .todayPatch: +// return ["Content-Type": "application/json"] +// case .createTodayPopo(_, _, _): +// return [ +// "Content-Type": "multipart/form-data", +// "Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImVtYWlsIjoidGVzdEB0ZXN0LmNvbSIsImlhdCI6MTYyOTExMjcyNCwiZXhwIjoxNjMxNzA0NzI0LCJpc3MiOiJmb3J0aWNlIn0.CkrwwZe7sJ9RxLbkbbeIz-w4fs2AkQ-FrERDcZNQI2E" +// ] +// case .patchTodayImage: +// return [ +// "Content-Type": "multipart/form-data", +// "Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImVtYWlsIjoidGVzdEB0ZXN0LmNvbSIsImlhdCI6MTYyOTExMjcyNCwiZXhwIjoxNjMxNzA0NzI0LCJpc3MiOiJmb3J0aWNlIn0.CkrwwZe7sJ9RxLbkbbeIz-w4fs2AkQ-FrERDcZNQI2E" +// ] +// } +// } +//} diff --git a/Podfile.lock b/Podfile.lock index b11d5263..01242911 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,22 +1,22 @@ PODS: - - Alamofire (5.4.3) - - KakaoSDKAuth (2.5.6): - - KakaoSDKCommon (= 2.5.6) - - KakaoSDKCommon (2.5.6): - - KakaoSDKCommon/Common (= 2.5.6) - - KakaoSDKCommon/Network (= 2.5.6) - - KakaoSDKCommon/Common (2.5.6) - - KakaoSDKCommon/Network (2.5.6): + - Alamofire (5.4.4) + - KakaoSDKAuth (2.8.2): + - KakaoSDKCommon (= 2.8.2) + - KakaoSDKCommon (2.8.2): + - KakaoSDKCommon/Common (= 2.8.2) + - KakaoSDKCommon/Network (= 2.8.2) + - KakaoSDKCommon/Common (2.8.2) + - KakaoSDKCommon/Network (2.8.2): - Alamofire (~> 5.1) - - KakaoSDKCommon/Common (= 2.5.6) - - KakaoSDKUser (2.5.6): - - KakaoSDKAuth (= 2.5.6) + - KakaoSDKCommon/Common (= 2.8.2) + - KakaoSDKUser (2.8.2): + - KakaoSDKAuth (= 2.8.2) - Moya (14.0.0): - Moya/Core (= 14.0.0) - Moya/Core (14.0.0): - Alamofire (~> 5.0) - - SkeletonView (1.21.2) - - SwiftLint (0.43.1) + - SkeletonView (1.25.2) + - SwiftLint (0.45.0) - VerticalCardSwiper (2.3.1) DEPENDENCIES: @@ -38,13 +38,13 @@ SPEC REPOS: - VerticalCardSwiper SPEC CHECKSUMS: - Alamofire: e447a2774a40c996748296fa2c55112fdbbc42f9 - KakaoSDKAuth: 1e1fa737e78eed3f301ab5c164526781a37a42f9 - KakaoSDKCommon: cdf340a8f671eef75f4ca012003cb350af3c4b6d - KakaoSDKUser: f488aa4699b3fd3a836ab5c7e25e2cb4cea190c1 + Alamofire: f3b09a368f1582ab751b3fff5460276e0d2cf5c9 + KakaoSDKAuth: 2b7e6998d7028cabd037ef8d0d2f987b4eec9f89 + KakaoSDKCommon: 1b5dc1c785688bed6d6747d05f2c8e08420f09ff + KakaoSDKUser: 937f1acc1380192d38483480d5bf01b141471829 Moya: 5b45dacb75adb009f97fde91c204c1e565d31916 - SkeletonView: a085533443fed0198309f1979780afb6e80eaedd - SwiftLint: 99f82d07b837b942dd563c668de129a03fc3fb52 + SkeletonView: 820b2bbd180d7408f3f03b6462cfc3cac39d2ef2 + SwiftLint: e5c7f1fba68eccfc51509d5b2ce1699f5502e0c7 VerticalCardSwiper: 68df635b354500f86934ea044ade37a264c044c6 PODFILE CHECKSUM: ed90d25629de2c0d09e14aa4277ccf85ccb9037a