From 7e9468f036ee4fd639826d40c93d4fe8c41ac97d Mon Sep 17 00:00:00 2001 From: suyeon Date: Mon, 16 May 2022 23:26:43 +0900 Subject: [PATCH 01/30] =?UTF-8?q?[FEAT]=20APIEnvironment=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 3 +++ .../Network/Foundation/APIEnvironment.swift | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index cda97a2..686920d 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 4D22C0CB27FB8A5E005F3A73 /* MakeNameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CA27FB8A5E005F3A73 /* MakeNameViewController.swift */; }; 4D22C0CD27FB8C6C005F3A73 /* MakePasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */; }; 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */; }; + 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */; }; 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2228136965006CABC1 /* BackButton.swift */; }; 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B25281379D7006CABC1 /* TabBarController.swift */; }; 4DD40B2E28137A8B006CABC1 /* FeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2D28137A8B006CABC1 /* FeedViewController.swift */; }; @@ -36,6 +37,7 @@ 4D22C0CA27FB8A5E005F3A73 /* MakeNameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeNameViewController.swift; sourceTree = ""; }; 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakePasswordViewController.swift; sourceTree = ""; }; 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompleteLoginViewController.swift; sourceTree = ""; }; + 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIEnvironment.swift; sourceTree = ""; }; 4DD40B2228136965006CABC1 /* BackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackButton.swift; sourceTree = ""; }; 4DD40B25281379D7006CABC1 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; 4DD40B2D28137A8B006CABC1 /* FeedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedViewController.swift; sourceTree = ""; }; @@ -323,6 +325,7 @@ 4DD4DBBF27FA43AC00E54124 /* UIView+.swift in Sources */, 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */, 4D22C0C927FB74FD005F3A73 /* InstaButton.swift in Sources */, + 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */, 4DD40B3428137ABA006CABC1 /* ShopViewController.swift in Sources */, 4D22C0CB27FB8A5E005F3A73 /* MakeNameViewController.swift in Sources */, 4DD40B3628137AC4006CABC1 /* ProfileViewController.swift in Sources */, diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift new file mode 100644 index 0000000..43f4b6c --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift @@ -0,0 +1,24 @@ +// +// APIEnvironment.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation + +enum APIEnvironment: String, CaseIterable { + case development + case production +} + +extension APIEnvironment { + var baseUrl: String { + switch self { + case .development: + return "http://13.124.62.236/" + case .production: + return "" + } + } +} From a4ac9631bda25e08ce74b6a1819cdb8433afc67b Mon Sep 17 00:00:00 2001 From: suyeon Date: Mon, 16 May 2022 23:27:47 +0900 Subject: [PATCH 02/30] =?UTF-8?q?[FEAT]=20Constants=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 6 ++++++ .../Network/Foundation/NetworkConstants.swift | 13 +++++++++++++ .../Network/Foundation/URLConstants.swift | 14 ++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index 686920d..d45a42b 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 4D22C0CD27FB8C6C005F3A73 /* MakePasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */; }; 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */; }; 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */; }; + 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */; }; + 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2732832951900A3DD31 /* URLConstants.swift */; }; 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2228136965006CABC1 /* BackButton.swift */; }; 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B25281379D7006CABC1 /* TabBarController.swift */; }; 4DD40B2E28137A8B006CABC1 /* FeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2D28137A8B006CABC1 /* FeedViewController.swift */; }; @@ -38,6 +40,8 @@ 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakePasswordViewController.swift; sourceTree = ""; }; 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompleteLoginViewController.swift; sourceTree = ""; }; 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIEnvironment.swift; sourceTree = ""; }; + 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConstants.swift; sourceTree = ""; }; + 4D32E2732832951900A3DD31 /* URLConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLConstants.swift; sourceTree = ""; }; 4DD40B2228136965006CABC1 /* BackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackButton.swift; sourceTree = ""; }; 4DD40B25281379D7006CABC1 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; 4DD40B2D28137A8B006CABC1 /* FeedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedViewController.swift; sourceTree = ""; }; @@ -323,6 +327,7 @@ files = ( 4DD40B3028137A9A006CABC1 /* SearchViewController.swift in Sources */, 4DD4DBBF27FA43AC00E54124 /* UIView+.swift in Sources */, + 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */, 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */, 4D22C0C927FB74FD005F3A73 /* InstaButton.swift in Sources */, 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */, @@ -338,6 +343,7 @@ 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */, 4D22C0CD27FB8C6C005F3A73 /* MakePasswordViewController.swift in Sources */, 4DD4DB9427FA171D00E54124 /* AppDelegate.swift in Sources */, + 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */, 4DD40B3228137AAD006CABC1 /* ReelsViewController.swift in Sources */, 4DD4DB9627FA171D00E54124 /* SceneDelegate.swift in Sources */, ); diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift new file mode 100644 index 0000000..2d54964 --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift @@ -0,0 +1,13 @@ +// +// NetworkConstants.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation + +struct NetworkConstants { + + static let header = ["Content-Type": "application/json"] +} diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift new file mode 100644 index 0000000..022289f --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift @@ -0,0 +1,14 @@ +// +// URLConstants.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation + +struct URLConstants { + + static let authSignup = "/auth/signup" + static let authSignin = "/auth/signin" +} From fd2298c0d40f47782ed71e01bb02a3b8436f7dac Mon Sep 17 00:00:00 2001 From: suyeon Date: Mon, 16 May 2022 23:29:34 +0900 Subject: [PATCH 03/30] =?UTF-8?q?[ADD]=20Genaral=20Response=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 3 ++ .../Network/Model/GenaralResponse.swift | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Model/GenaralResponse.swift diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index d45a42b..87caca3 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */; }; 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */; }; 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */; }; + 4D32E26E28328F2900A3DD31 /* GenaralResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */; }; 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2732832951900A3DD31 /* URLConstants.swift */; }; 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2228136965006CABC1 /* BackButton.swift */; }; 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B25281379D7006CABC1 /* TabBarController.swift */; }; @@ -41,6 +42,7 @@ 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompleteLoginViewController.swift; sourceTree = ""; }; 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIEnvironment.swift; sourceTree = ""; }; 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConstants.swift; sourceTree = ""; }; + 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenaralResponse.swift; sourceTree = ""; }; 4D32E2732832951900A3DD31 /* URLConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLConstants.swift; sourceTree = ""; }; 4DD40B2228136965006CABC1 /* BackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackButton.swift; sourceTree = ""; }; 4DD40B25281379D7006CABC1 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; @@ -326,6 +328,7 @@ buildActionMask = 2147483647; files = ( 4DD40B3028137A9A006CABC1 /* SearchViewController.swift in Sources */, + 4D32E26E28328F2900A3DD31 /* GenaralResponse.swift in Sources */, 4DD4DBBF27FA43AC00E54124 /* UIView+.swift in Sources */, 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */, 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */, diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Model/GenaralResponse.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Model/GenaralResponse.swift new file mode 100644 index 0000000..256a422 --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Model/GenaralResponse.swift @@ -0,0 +1,30 @@ +// +// GenaralResponse.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation + +struct GeneralResponse: Codable { + var status: Int + var success: Bool? + var message: String? + var data: T? + + enum CodingKeys: String, CodingKey { + case status = "status" + case success = "success" + case message = "message" + case data = "data" + } + + init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + status = (try? values.decode(Int.self, forKey: .status)) ?? -1 + success = (try? values.decode(Bool.self, forKey: .success)) ?? false + message = (try? values.decode(String.self, forKey: .message)) ?? "" + data = (try? values.decode(T.self, forKey: .data)) ?? nil + } +} From fc35acfe7f6a39a8dfb6bd61b84809d51d337cdc Mon Sep 17 00:00:00 2001 From: suyeon Date: Mon, 16 May 2022 23:30:20 +0900 Subject: [PATCH 04/30] =?UTF-8?q?[ADD]=20Network=20Result=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 3 +++ .../Network/Foundation/NetworkResult.swift | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkResult.swift diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index 87caca3..58f1545 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 4D22C0CD27FB8C6C005F3A73 /* MakePasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */; }; 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */; }; 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */; }; + 4D32E26628328DE300A3DD31 /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26528328DE300A3DD31 /* NetworkResult.swift */; }; 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */; }; 4D32E26E28328F2900A3DD31 /* GenaralResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */; }; 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2732832951900A3DD31 /* URLConstants.swift */; }; @@ -41,6 +42,7 @@ 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakePasswordViewController.swift; sourceTree = ""; }; 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompleteLoginViewController.swift; sourceTree = ""; }; 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIEnvironment.swift; sourceTree = ""; }; + 4D32E26528328DE300A3DD31 /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = ""; }; 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConstants.swift; sourceTree = ""; }; 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenaralResponse.swift; sourceTree = ""; }; 4D32E2732832951900A3DD31 /* URLConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLConstants.swift; sourceTree = ""; }; @@ -340,6 +342,7 @@ 4DF86F5827FF72DB009DCFAA /* ImageLiteral.swift in Sources */, 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */, 4DD40B2E28137A8B006CABC1 /* FeedViewController.swift in Sources */, + 4D32E26628328DE300A3DD31 /* NetworkResult.swift in Sources */, 4DD4DBBB27FA3A0600E54124 /* BaseViewController.swift in Sources */, 4DD4DBBD27FA3E6100E54124 /* InstaTextField.swift in Sources */, 4DD4DBB927FA39F800E54124 /* LoginViewController.swift in Sources */, diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkResult.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkResult.swift new file mode 100644 index 0000000..4e27907 --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkResult.swift @@ -0,0 +1,16 @@ +// +// NetworkResult.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation + +enum NetworkResult { + case success(T) + case requestErr(T) + case pathErr + case serverErr + case networkFail +} From 6ff289656d041b1572071f11fe6ed458b34be4be Mon Sep 17 00:00:00 2001 From: suyeon Date: Mon, 16 May 2022 23:31:00 +0900 Subject: [PATCH 05/30] =?UTF-8?q?[FEAT]=20GeneralService=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 3 ++ .../Network/Foundation/GeneralService.swift | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index 58f1545..ae40457 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */; }; 4D32E26628328DE300A3DD31 /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26528328DE300A3DD31 /* NetworkResult.swift */; }; 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */; }; + 4D32E26C28328E1F00A3DD31 /* GeneralService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26B28328E1F00A3DD31 /* GeneralService.swift */; }; 4D32E26E28328F2900A3DD31 /* GenaralResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */; }; 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2732832951900A3DD31 /* URLConstants.swift */; }; 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2228136965006CABC1 /* BackButton.swift */; }; @@ -44,6 +45,7 @@ 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIEnvironment.swift; sourceTree = ""; }; 4D32E26528328DE300A3DD31 /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = ""; }; 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConstants.swift; sourceTree = ""; }; + 4D32E26B28328E1F00A3DD31 /* GeneralService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralService.swift; sourceTree = ""; }; 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenaralResponse.swift; sourceTree = ""; }; 4D32E2732832951900A3DD31 /* URLConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLConstants.swift; sourceTree = ""; }; 4DD40B2228136965006CABC1 /* BackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackButton.swift; sourceTree = ""; }; @@ -339,6 +341,7 @@ 4DD40B3428137ABA006CABC1 /* ShopViewController.swift in Sources */, 4D22C0CB27FB8A5E005F3A73 /* MakeNameViewController.swift in Sources */, 4DD40B3628137AC4006CABC1 /* ProfileViewController.swift in Sources */, + 4D32E26C28328E1F00A3DD31 /* GeneralService.swift in Sources */, 4DF86F5827FF72DB009DCFAA /* ImageLiteral.swift in Sources */, 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */, 4DD40B2E28137A8B006CABC1 /* FeedViewController.swift in Sources */, diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift new file mode 100644 index 0000000..41dae6b --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift @@ -0,0 +1,30 @@ +// +// GeneralResponse.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation + +struct GeneralService { + + static func judgeStatus(by statusCode: Int, _ data: Data, _ type: T.Type) -> NetworkResult { + let decoder = JSONDecoder() + guard let decodedData = try? decoder.decode(GeneralResponse.self, from: data) + else { return .pathErr } + print(decodedData) + switch statusCode { + case 200: + return .success(decodedData.data ?? "None-Data") + case 201..<300: + return .success(decodedData.status) + case 400..<500: + return .requestErr(decodedData.status) + case 500: + return .serverErr + default: + return .networkFail + } + } +} From 0187bc8cc991e97f11b38ed2b69a6bea35ca5729 Mon Sep 17 00:00:00 2001 From: suyeon Date: Mon, 16 May 2022 23:31:13 +0900 Subject: [PATCH 06/30] =?UTF-8?q?[FEAT]=20=EB=84=A4=ED=8A=B8=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=20=EA=B8=B0=EB=B3=B8=20=ED=8C=8C=EC=9D=BC=20=EC=84=B8?= =?UTF-8?q?=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 62 +++++++++++++++++++ .../Network/Foundation/NeworkRequest.swift | 8 +++ .../30th-Assignment/Network/Model/Auth.swift | 16 +++++ .../Network/Router/AuthRouter.swift | 8 +++ .../Network/Service/AuthService.swift | 9 +++ 5 files changed, 103 insertions(+) create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Model/Auth.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index ae40457..7fefcba 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -13,10 +13,14 @@ 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */; }; 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */; }; 4D32E26628328DE300A3DD31 /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26528328DE300A3DD31 /* NetworkResult.swift */; }; + 4D32E26828328DF900A3DD31 /* NeworkRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26728328DF900A3DD31 /* NeworkRequest.swift */; }; 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */; }; 4D32E26C28328E1F00A3DD31 /* GeneralService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26B28328E1F00A3DD31 /* GeneralService.swift */; }; 4D32E26E28328F2900A3DD31 /* GenaralResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */; }; + 4D32E27028328FB400A3DD31 /* AuthRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26F28328FB400A3DD31 /* AuthRouter.swift */; }; + 4D32E27228328FC300A3DD31 /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E27128328FC300A3DD31 /* AuthService.swift */; }; 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2732832951900A3DD31 /* URLConstants.swift */; }; + 4D32E2762832961400A3DD31 /* Auth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2752832961300A3DD31 /* Auth.swift */; }; 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2228136965006CABC1 /* BackButton.swift */; }; 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B25281379D7006CABC1 /* TabBarController.swift */; }; 4DD40B2E28137A8B006CABC1 /* FeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2D28137A8B006CABC1 /* FeedViewController.swift */; }; @@ -44,10 +48,14 @@ 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompleteLoginViewController.swift; sourceTree = ""; }; 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIEnvironment.swift; sourceTree = ""; }; 4D32E26528328DE300A3DD31 /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = ""; }; + 4D32E26728328DF900A3DD31 /* NeworkRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeworkRequest.swift; sourceTree = ""; }; 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConstants.swift; sourceTree = ""; }; 4D32E26B28328E1F00A3DD31 /* GeneralService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralService.swift; sourceTree = ""; }; 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenaralResponse.swift; sourceTree = ""; }; + 4D32E26F28328FB400A3DD31 /* AuthRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRouter.swift; sourceTree = ""; }; + 4D32E27128328FC300A3DD31 /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthService.swift; sourceTree = ""; }; 4D32E2732832951900A3DD31 /* URLConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLConstants.swift; sourceTree = ""; }; + 4D32E2752832961300A3DD31 /* Auth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Auth.swift; sourceTree = ""; }; 4DD40B2228136965006CABC1 /* BackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackButton.swift; sourceTree = ""; }; 4DD40B25281379D7006CABC1 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; 4DD40B2D28137A8B006CABC1 /* FeedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedViewController.swift; sourceTree = ""; }; @@ -81,6 +89,55 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4D32E25E28328D1A00A3DD31 /* Network */ = { + isa = PBXGroup; + children = ( + 4D32E25F28328D5900A3DD31 /* Foundation */, + 4D32E26028328D6C00A3DD31 /* Model */, + 4D32E26128328D7300A3DD31 /* Router */, + 4D32E26228328D9D00A3DD31 /* Service */, + ); + path = Network; + sourceTree = ""; + }; + 4D32E25F28328D5900A3DD31 /* Foundation */ = { + isa = PBXGroup; + children = ( + 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */, + 4D32E26528328DE300A3DD31 /* NetworkResult.swift */, + 4D32E26728328DF900A3DD31 /* NeworkRequest.swift */, + 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */, + 4D32E26B28328E1F00A3DD31 /* GeneralService.swift */, + 4D32E2732832951900A3DD31 /* URLConstants.swift */, + ); + path = Foundation; + sourceTree = ""; + }; + 4D32E26028328D6C00A3DD31 /* Model */ = { + isa = PBXGroup; + children = ( + 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */, + 4D32E2752832961300A3DD31 /* Auth.swift */, + ); + path = Model; + sourceTree = ""; + }; + 4D32E26128328D7300A3DD31 /* Router */ = { + isa = PBXGroup; + children = ( + 4D32E26F28328FB400A3DD31 /* AuthRouter.swift */, + ); + path = Router; + sourceTree = ""; + }; + 4D32E26228328D9D00A3DD31 /* Service */ = { + isa = PBXGroup; + children = ( + 4D32E27128328FC300A3DD31 /* AuthService.swift */, + ); + path = Service; + sourceTree = ""; + }; 4DD40B24281379AB006CABC1 /* Tabbar */ = { isa = PBXGroup; children = ( @@ -148,6 +205,7 @@ 4DD4DB9227FA171D00E54124 /* 30th-Assignment */ = { isa = PBXGroup; children = ( + 4D32E25E28328D1A00A3DD31 /* Network */, 4DD4DBA727FA17E200E54124 /* Global */, 4DD4DBA827FA17F200E54124 /* Screens */, ); @@ -341,6 +399,8 @@ 4DD40B3428137ABA006CABC1 /* ShopViewController.swift in Sources */, 4D22C0CB27FB8A5E005F3A73 /* MakeNameViewController.swift in Sources */, 4DD40B3628137AC4006CABC1 /* ProfileViewController.swift in Sources */, + 4D32E26828328DF900A3DD31 /* NeworkRequest.swift in Sources */, + 4D32E2762832961400A3DD31 /* Auth.swift in Sources */, 4D32E26C28328E1F00A3DD31 /* GeneralService.swift in Sources */, 4DF86F5827FF72DB009DCFAA /* ImageLiteral.swift in Sources */, 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */, @@ -349,9 +409,11 @@ 4DD4DBBB27FA3A0600E54124 /* BaseViewController.swift in Sources */, 4DD4DBBD27FA3E6100E54124 /* InstaTextField.swift in Sources */, 4DD4DBB927FA39F800E54124 /* LoginViewController.swift in Sources */, + 4D32E27228328FC300A3DD31 /* AuthService.swift in Sources */, 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */, 4D22C0CD27FB8C6C005F3A73 /* MakePasswordViewController.swift in Sources */, 4DD4DB9427FA171D00E54124 /* AppDelegate.swift in Sources */, + 4D32E27028328FB400A3DD31 /* AuthRouter.swift in Sources */, 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */, 4DD40B3228137AAD006CABC1 /* ReelsViewController.swift in Sources */, 4DD4DB9627FA171D00E54124 /* SceneDelegate.swift in Sources */, diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift new file mode 100644 index 0000000..696695e --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift @@ -0,0 +1,8 @@ +// +// NeworkRequest.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Model/Auth.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Model/Auth.swift new file mode 100644 index 0000000..d5e34cb --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Model/Auth.swift @@ -0,0 +1,16 @@ +// +// Auth.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation + +struct SignIn: Codable { + let name, email: String +} + +struct SignUp: Codable { + let id: Int +} diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift new file mode 100644 index 0000000..c3a3ea5 --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift @@ -0,0 +1,8 @@ +// +// AuthRouter.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift new file mode 100644 index 0000000..ad1e210 --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift @@ -0,0 +1,9 @@ +// +// AuthService.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/16. +// + +import Foundation + From 42758bfbb19a63a1d656ece4f95ccfb0228b3281 Mon Sep 17 00:00:00 2001 From: suyeon Date: Mon, 16 May 2022 23:58:42 +0900 Subject: [PATCH 07/30] =?UTF-8?q?[ADD]=20Alamofire=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 17 +++++++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index 7fefcba..c50a942 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 4D32E27228328FC300A3DD31 /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E27128328FC300A3DD31 /* AuthService.swift */; }; 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2732832951900A3DD31 /* URLConstants.swift */; }; 4D32E2762832961400A3DD31 /* Auth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2752832961300A3DD31 /* Auth.swift */; }; + 4D32E27C28329E0C00A3DD31 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 4D32E27B28329E0C00A3DD31 /* Alamofire */; }; 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2228136965006CABC1 /* BackButton.swift */; }; 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B25281379D7006CABC1 /* TabBarController.swift */; }; 4DD40B2E28137A8B006CABC1 /* FeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2D28137A8B006CABC1 /* FeedViewController.swift */; }; @@ -81,6 +82,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 4D32E27C28329E0C00A3DD31 /* Alamofire in Frameworks */, 4DD4DBB327FA1FDA00E54124 /* Then in Frameworks */, 4DD4DBB627FA1FEE00E54124 /* SnapKit in Frameworks */, ); @@ -330,6 +332,7 @@ packageProductDependencies = ( 4DD4DBB227FA1FDA00E54124 /* Then */, 4DD4DBB527FA1FEE00E54124 /* SnapKit */, + 4D32E27B28329E0C00A3DD31 /* Alamofire */, ); productName = "30th-Assignment"; productReference = 4DD4DB9027FA171D00E54124 /* 30th-Assignment.app */; @@ -362,6 +365,7 @@ packageReferences = ( 4DD4DBB127FA1FDA00E54124 /* XCRemoteSwiftPackageReference "Then" */, 4DD4DBB427FA1FEE00E54124 /* XCRemoteSwiftPackageReference "SnapKit" */, + 4D32E27A28329E0C00A3DD31 /* XCRemoteSwiftPackageReference "Alamofire" */, ); productRefGroup = 4DD4DB9127FA171D00E54124 /* Products */; projectDirPath = ""; @@ -626,6 +630,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + 4D32E27A28329E0C00A3DD31 /* XCRemoteSwiftPackageReference "Alamofire" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Alamofire/Alamofire"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.0.0; + }; + }; 4DD4DBB127FA1FDA00E54124 /* XCRemoteSwiftPackageReference "Then" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/devxoul/Then"; @@ -645,6 +657,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 4D32E27B28329E0C00A3DD31 /* Alamofire */ = { + isa = XCSwiftPackageProductDependency; + package = 4D32E27A28329E0C00A3DD31 /* XCRemoteSwiftPackageReference "Alamofire" */; + productName = Alamofire; + }; 4DD4DBB227FA1FDA00E54124 /* Then */ = { isa = XCSwiftPackageProductDependency; package = 4DD4DBB127FA1FDA00E54124 /* XCRemoteSwiftPackageReference "Then" */; diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 68a47e6..e27fc7e 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,14 @@ { "pins" : [ + { + "identity" : "alamofire", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Alamofire/Alamofire", + "state" : { + "revision" : "354dda32d89fc8cd4f5c46487f64957d355f53d8", + "version" : "5.6.1" + } + }, { "identity" : "snapkit", "kind" : "remoteSourceControl", From 1f01fdc95ea095cf76eef5525b83e7a969659ee9 Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 01:27:37 +0900 Subject: [PATCH 08/30] =?UTF-8?q?[ADD]=20Alert=20Extension=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 4 ++ .../Global/Extension/UIViewController+.swift | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Global/Extension/UIViewController+.swift diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index c50a942..855ad40 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2732832951900A3DD31 /* URLConstants.swift */; }; 4D32E2762832961400A3DD31 /* Auth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E2752832961300A3DD31 /* Auth.swift */; }; 4D32E27C28329E0C00A3DD31 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 4D32E27B28329E0C00A3DD31 /* Alamofire */; }; + 4D32E27E2832B25500A3DD31 /* UIViewController+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E27D2832B25500A3DD31 /* UIViewController+.swift */; }; 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2228136965006CABC1 /* BackButton.swift */; }; 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B25281379D7006CABC1 /* TabBarController.swift */; }; 4DD40B2E28137A8B006CABC1 /* FeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD40B2D28137A8B006CABC1 /* FeedViewController.swift */; }; @@ -57,6 +58,7 @@ 4D32E27128328FC300A3DD31 /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthService.swift; sourceTree = ""; }; 4D32E2732832951900A3DD31 /* URLConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLConstants.swift; sourceTree = ""; }; 4D32E2752832961300A3DD31 /* Auth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Auth.swift; sourceTree = ""; }; + 4D32E27D2832B25500A3DD31 /* UIViewController+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+.swift"; sourceTree = ""; }; 4DD40B2228136965006CABC1 /* BackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackButton.swift; sourceTree = ""; }; 4DD40B25281379D7006CABC1 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; 4DD40B2D28137A8B006CABC1 /* FeedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedViewController.swift; sourceTree = ""; }; @@ -261,6 +263,7 @@ isa = PBXGroup; children = ( 4DD4DBBE27FA43AC00E54124 /* UIView+.swift */, + 4D32E27D2832B25500A3DD31 /* UIViewController+.swift */, ); path = Extension; sourceTree = ""; @@ -417,6 +420,7 @@ 4DD40B2328136965006CABC1 /* BackButton.swift in Sources */, 4D22C0CD27FB8C6C005F3A73 /* MakePasswordViewController.swift in Sources */, 4DD4DB9427FA171D00E54124 /* AppDelegate.swift in Sources */, + 4D32E27E2832B25500A3DD31 /* UIViewController+.swift in Sources */, 4D32E27028328FB400A3DD31 /* AuthRouter.swift in Sources */, 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */, 4DD40B3228137AAD006CABC1 /* ReelsViewController.swift in Sources */, diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Global/Extension/UIViewController+.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Global/Extension/UIViewController+.swift new file mode 100644 index 0000000..75924e0 --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Global/Extension/UIViewController+.swift @@ -0,0 +1,46 @@ +// +// UIViewController+.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/17. +// + +import UIKit + +extension UIViewController { + + /// 확인 버튼 1개, 취소 버튼 1개 Alert 메서드 + func makeAlertWithCancel(okTitle: String, okStyle: UIAlertAction.Style = .default, + cancelTitle: String = "취소", + okAction : ((UIAlertAction) -> Void)?, cancelAction : ((UIAlertAction) -> Void)? = nil, + completion : (() -> Void)? = nil) { + + let generator = UIImpactFeedbackGenerator(style: .medium) + generator.impactOccurred() + + let alertViewController = UIAlertController(title: nil, message: nil, + preferredStyle: .actionSheet) + + let okAction = UIAlertAction(title: okTitle, style: okStyle, handler: okAction) + alertViewController.addAction(okAction) + + let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel, handler: cancelAction) + alertViewController.addAction(cancelAction) + + self.present(alertViewController, animated: true, completion: completion) + } + + /// 확인 버튼 Alert 메서드 + func makeAlert(title : String, message : String? = nil, + okTitle: String = "확인", okAction : ((UIAlertAction) -> Void)? = nil, + completion : (() -> Void)? = nil) { + let generator = UIImpactFeedbackGenerator(style: .medium) + generator.impactOccurred() + let alertViewController = UIAlertController(title: title, message: message, + preferredStyle: .alert) + let okAction = UIAlertAction(title: okTitle, style: .default, handler: okAction) + alertViewController.addAction(okAction) + self.present(alertViewController, animated: true, completion: completion) + } + +} From b85a5095d539a4222e787abb7bc9c1f535cb206d Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 01:28:05 +0900 Subject: [PATCH 09/30] =?UTF-8?q?[FEAT]=20Network=20=EC=83=81=EC=88=98=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Network/Foundation/NetworkConstants.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift index 2d54964..392d6ca 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift @@ -7,7 +7,18 @@ import Foundation -struct NetworkConstants { +enum HeaderType { + case basic + case auth +} + +enum HTTPHeaderField: String { + case authentication = "Authorization" + case contentType = "Content-Type" + case accesstoken = "accesstoken" +} - static let header = ["Content-Type": "application/json"] +enum ContentType: String { + case json = "Application/json" + case tokenSerial = "" } From fbadde4c9d881f86b3ad426ffa42e1066a89c20b Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 01:28:29 +0900 Subject: [PATCH 10/30] =?UTF-8?q?[FEAT]=20URL=20=EC=83=81=EC=88=98=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment/Network/Foundation/URLConstants.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift index 022289f..cd285aa 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift @@ -9,6 +9,6 @@ import Foundation struct URLConstants { - static let authSignup = "/auth/signup" - static let authSignin = "/auth/signin" + static let signUp = "/auth/signup" + static let signIn = "/auth/signin" } From 31663d8050bbbe978ca00a1374fd75821870bf3e Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 01:29:02 +0900 Subject: [PATCH 11/30] =?UTF-8?q?[FEAT]=20BaseRouter=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Network/Foundation/NeworkRequest.swift | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift index 696695e..8a5d4f4 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift @@ -6,3 +6,82 @@ // import Foundation +import Alamofire + +protocol Router: URLRequestConvertible { + var baseURL: String { get } + var method: HTTPMethod { get } + var path: String { get } + var parameters: RequestParams { get } + var header: HeaderType { get } +} + +extension Router { + var baseURL: String { + return APIEnvironment.development.baseUrl + } + + // URLRequestConvertible 구현 + func asURLRequest() throws -> URLRequest { + let url = try baseURL.asURL() + var urlRequest = try URLRequest(url: url.appendingPathComponent(path), method: method) + + urlRequest = self.makeHeaderForRequest(to: urlRequest) + + return try self.makePrameterForRequest(to: urlRequest, with: url) + } + + private func makeHeaderForRequest(to request: URLRequest) -> URLRequest { + var request = request + + switch header { + case .basic: + request.setValue(ContentType.json.rawValue, forHTTPHeaderField: HTTPHeaderField.contentType.rawValue) + + case .auth: + request.setValue(ContentType.json.rawValue, forHTTPHeaderField: HTTPHeaderField.contentType.rawValue) + request.setValue(ContentType.tokenSerial.rawValue, forHTTPHeaderField: HTTPHeaderField.accesstoken.rawValue) + } + + return request + } + + private func makePrameterForRequest(to request: URLRequest, with url: URL) throws -> URLRequest { + var request = request + + switch parameters { + case .query(let query): + let params = query?.toDictionary() ?? [:] + let queryParams = params.map { URLQueryItem(name: $0.key, value: "\($0.value)") } + var components = URLComponents(string: url.appendingPathComponent(path).absoluteString) + components?.queryItems = queryParams + request.url = components?.url + + case .body(let body): + let params = body?.toDictionary() ?? [:] + request.httpBody = try JSONSerialization.data(withJSONObject: params, options: []) + + case .requestParameters(let requestParams): + let params = requestParams + request.httpBody = try JSONSerialization.data(withJSONObject: params, options: []) + } + + return request + } +} + +enum RequestParams { + case query(_ parameter: Codable?) + case body(_ parameter: Codable?) + case requestParameters(_ parameter: [String : Any]) +} + +extension Encodable { + func toDictionary() -> [String: Any] { + guard let data = try? JSONEncoder().encode(self), + let jsonData = try? JSONSerialization.jsonObject(with: data), + let dictionaryData = jsonData as? [String: Any] else { return [:] } + return dictionaryData + } +} + From f94b904e761c045d0509c2a897cfa03164da9e87 Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 01:29:20 +0900 Subject: [PATCH 12/30] =?UTF-8?q?[FEAT]=20AuthRouter=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Network/Router/AuthRouter.swift | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift index c3a3ea5..de9b55f 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift @@ -6,3 +6,53 @@ // import Foundation +import Alamofire + +enum AuthRouter { + case signIn(email: String, pw: String) + case signUp(email: String, name: String, pw: String) +} + +extension AuthRouter: Router { + + var path: String { + switch self { + case .signIn: + return URLConstants.signIn + case .signUp: + return URLConstants.signUp + } + } + + var method: HTTPMethod { + switch self { + case .signIn, .signUp: + return .post + } + } + + var header: HeaderType { + switch self { + case .signIn, .signUp: + return .basic + } + } + + var parameters: RequestParams { + switch self { + case .signUp(let email, let name, let pw): + let body: [String:Any] = [ + "email": email, + "name": name, + "password":pw + ] + return .requestParameters(body) + case .signIn(let email, let pw): + let body: [String:Any] = [ + "email": email, + "password": pw + ] + return .requestParameters(body) + } + } +} From bbf490ab4fcc4cdc89d1776929b981436b0f1abc Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 01:29:40 +0900 Subject: [PATCH 13/30] =?UTF-8?q?[FEAT]=20AuthService=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Network/Service/AuthService.swift | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift index ad1e210..6278267 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift @@ -6,4 +6,46 @@ // import Foundation +import Alamofire +struct AuthService { + static let shared = AuthService() + + /// [POST] 로그인 + func requestSignIn(email: String, pw: String, completion: @escaping (NetworkResult) -> (Void)) { + AF.request(AuthRouter.signIn(email: email, pw: pw)) + .validate(statusCode: 200...500) + .responseData { response in + switch response.result { + case .success: + guard let statusCode = response.response?.statusCode else { return } + guard let data = response.data else { return } + let networkResult = GeneralService.judgeStatus(by: statusCode, data, SignIn.self) + + completion(networkResult) + + case .failure(let err): + print(err.localizedDescription) + } + } + + } + /// [POST] 회원가입 + func requestSignUp(email: String, name: String, pw: String, completion: @escaping (NetworkResult) -> (Void)) { + AF.request(AuthRouter.signUp(email: email, name: name, pw: pw)) + .validate(statusCode: 200...500) + .responseData { response in + switch response.result { + case .success: + guard let statusCode = response.response?.statusCode else { return } + guard let data = response.data else { return} + let networkResult = GeneralService.judgeStatus(by: statusCode, data, SignUp.self) + + completion(networkResult) + + case .failure(let err): + print(err.localizedDescription) + } + } + } +} From 51267573b2fe202e88b209d4c3bfd4b0433db640 Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 02:00:05 +0900 Subject: [PATCH 14/30] =?UTF-8?q?[FEAT]=20SignIn=20=EB=84=A4=ED=8A=B8?= =?UTF-8?q?=EC=9B=8C=ED=81=AC=20=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Network/Service/AuthService.swift | 1 - .../Authentication/LoginViewController.swift | 29 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift index 6278267..b7e9ba6 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift @@ -28,7 +28,6 @@ struct AuthService { print(err.localizedDescription) } } - } /// [POST] 회원가입 func requestSignUp(email: String, name: String, pw: String, completion: @escaping (NetworkResult) -> (Void)) { diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift index f63d90e..70ee73e 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift @@ -39,11 +39,13 @@ final class LoginViewController: BaseViewController { $0.isEnabled = false let completeViewAction = UIAction { _ in - let completeVC = CompleteLoginViewController() - completeVC.modalPresentationStyle = .fullScreen - completeVC.userName = self.emailTextField.text - self.present(completeVC, animated: true) + self.postSignIn(email: self.emailTextField.text ?? "", pw: self.passwordTextField.text ?? "") +// let completeVC = CompleteLoginViewController() +// +// completeVC.modalPresentationStyle = .fullScreen +// completeVC.userName = self.emailTextField.text +// self.present(completeVC, animated: true) } $0.addAction(completeViewAction, for: .touchUpInside) } @@ -143,6 +145,25 @@ final class LoginViewController: BaseViewController { /// 도전과제 (2) loginButton.isEnabled = [emailTextField, passwordTextField].allSatisfy { $0.hasText } } + + private func postSignIn(email: String, pw: String) { + AuthService.shared.requestSignIn(email: email, pw: pw) { result in + switch result { + case .success(let response): + if let message = response as? String { + self.makePresentAlert(title: message, nextVC: TabBarController()) + } + case .requestErr: + self.makeAlert(title: "아이디 또는 비밀번호를 확인해주세요.") + case .pathErr: + print("pathErr") + case .serverErr: + print("serverErr") + case .networkFail: + print("networkFail") + } + } + } } extension LoginViewController: UITextFieldDelegate { From 5a4adec818a75976ea20ddbee703f0d80f8c0e85 Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 02:00:19 +0900 Subject: [PATCH 15/30] =?UTF-8?q?[ADD]=20alert=20=EC=9D=B5=EC=8A=A4?= =?UTF-8?q?=ED=85=90=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Global/Extension/UIViewController+.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Global/Extension/UIViewController+.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Global/Extension/UIViewController+.swift index 75924e0..543c9d8 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Global/Extension/UIViewController+.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Global/Extension/UIViewController+.swift @@ -43,4 +43,17 @@ extension UIViewController { self.present(alertViewController, animated: true, completion: completion) } + /// 확인 버튼 누르면 화면전환되는 Alert 메서드 + func makePresentAlert(title : String, message : String? = nil, + okTitle: String = "확인", nextVC: UIViewController) { + let generator = UIImpactFeedbackGenerator(style: .medium) + generator.impactOccurred() + let alertViewController = UIAlertController(title: title, message: message, + preferredStyle: .alert) + alertViewController.addAction(UIAlertAction(title: okTitle, style: .default) { action in + nextVC.modalPresentationStyle = .fullScreen + self.present(nextVC, animated: true) + }) + self.present(alertViewController, animated: true, completion: nil) + } } From 57c6039a45f1016ed3879533e5e8316304392c4b Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 02:41:15 +0900 Subject: [PATCH 16/30] =?UTF-8?q?[CHORE]=20=EC=84=9C=EB=B2=84=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment/Global/Supports/Info.plist | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Global/Supports/Info.plist b/30th-Assignment/30th-Assignment/30th-Assignment/Global/Supports/Info.plist index 0eb786d..bc240fd 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Global/Supports/Info.plist +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Global/Supports/Info.plist @@ -2,6 +2,11 @@ + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + UIApplicationSceneManifest UIApplicationSupportsMultipleScenes From e595d9be797bc6b4f7bea4fee91b50ef16eb0918 Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 02:41:31 +0900 Subject: [PATCH 17/30] =?UTF-8?q?[CHORE]=20=EC=84=9C=EB=B2=84=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment/Network/Foundation/APIEnvironment.swift | 2 +- .../30th-Assignment/Network/Foundation/NetworkConstants.swift | 1 + .../Screens/Authentication/LoginViewController.swift | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift index 43f4b6c..76b96d2 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift @@ -16,7 +16,7 @@ extension APIEnvironment { var baseUrl: String { switch self { case .development: - return "http://13.124.62.236/" + return "http://13.124.62.236" case .production: return "" } diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift index 392d6ca..02fb293 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift @@ -6,6 +6,7 @@ // import Foundation +import Alamofire enum HeaderType { case basic diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift index 70ee73e..b67b433 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift @@ -39,7 +39,6 @@ final class LoginViewController: BaseViewController { $0.isEnabled = false let completeViewAction = UIAction { _ in - self.postSignIn(email: self.emailTextField.text ?? "", pw: self.passwordTextField.text ?? "") // let completeVC = CompleteLoginViewController() // From f2eab99df000843c26b0835f41b9db27d161b829 Mon Sep 17 00:00:00 2001 From: suyeon Date: Tue, 17 May 2022 08:40:06 +0900 Subject: [PATCH 18/30] =?UTF-8?q?[CHORE]=20=EC=84=9C=EB=B2=84=ED=86=B5?= =?UTF-8?q?=EC=8B=A0=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Authentication/LoginViewController.swift | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift index b67b433..97e5350 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift @@ -38,15 +38,15 @@ final class LoginViewController: BaseViewController { private lazy var loginButton = InstaButton(title: "로그인").then { $0.isEnabled = false - let completeViewAction = UIAction { _ in - self.postSignIn(email: self.emailTextField.text ?? "", pw: self.passwordTextField.text ?? "") + let LoginAction = UIAction { _ in + self.postSignIn() // let completeVC = CompleteLoginViewController() // // completeVC.modalPresentationStyle = .fullScreen // completeVC.userName = self.emailTextField.text // self.present(completeVC, animated: true) } - $0.addAction(completeViewAction, for: .touchUpInside) + $0.addAction(LoginAction, for: .touchUpInside) } private let signUpLabel = UILabel().then { @@ -145,13 +145,15 @@ final class LoginViewController: BaseViewController { loginButton.isEnabled = [emailTextField, passwordTextField].allSatisfy { $0.hasText } } - private func postSignIn(email: String, pw: String) { - AuthService.shared.requestSignIn(email: email, pw: pw) { result in + private func postSignIn() { + guard let email = emailTextField.text, + let password = passwordTextField.text + else { return } + + AuthService.shared.requestSignIn(email: email, pw: password) { result in switch result { - case .success(let response): - if let message = response as? String { - self.makePresentAlert(title: message, nextVC: TabBarController()) - } + case .success: + self.makePresentAlert(title: "로그인 성공", nextVC: TabBarController()) case .requestErr: self.makeAlert(title: "아이디 또는 비밀번호를 확인해주세요.") case .pathErr: From a1bca48a627bdb442513760ae3c26ef7efc832b8 Mon Sep 17 00:00:00 2001 From: suyeon Date: Wed, 18 May 2022 00:17:06 +0900 Subject: [PATCH 19/30] =?UTF-8?q?[FEAT]=20Alert=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=95=B4=EC=A3=BC=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Authentication/LoginViewController.swift | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift index 97e5350..6efa4d4 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift @@ -40,11 +40,6 @@ final class LoginViewController: BaseViewController { let LoginAction = UIAction { _ in self.postSignIn() -// let completeVC = CompleteLoginViewController() -// -// completeVC.modalPresentationStyle = .fullScreen -// completeVC.userName = self.emailTextField.text -// self.present(completeVC, animated: true) } $0.addAction(LoginAction, for: .touchUpInside) } @@ -154,8 +149,18 @@ final class LoginViewController: BaseViewController { switch result { case .success: self.makePresentAlert(title: "로그인 성공", nextVC: TabBarController()) - case .requestErr: - self.makeAlert(title: "아이디 또는 비밀번호를 확인해주세요.") + case .requestErr(let status): + guard let status = status as? Int else { return } + + switch status { + case 404: + self.makeAlert(title: "이메일에 해당하는 사용자정보가 없습니다.") + case 409: + self.makeAlert(title: "비밀번호가 올바르지 않습니다.") + default: + self.makeAlert(title: "아이디와 비밀번호를 다시 확인해주세요.") + } + case .pathErr: print("pathErr") case .serverErr: From 4b5c27ed1a3ba3220bf64ff5223df0e7e3d95696 Mon Sep 17 00:00:00 2001 From: suyeon Date: Wed, 18 May 2022 00:17:52 +0900 Subject: [PATCH 20/30] =?UTF-8?q?[FEAT]=20Service=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=83=81=EC=86=8D=EA=B4=80=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Network/Foundation/GeneralService.swift | 17 +++++++++++++++-- .../Network/Service/AuthService.swift | 12 +++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift index 41dae6b..650c0f9 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift @@ -7,9 +7,22 @@ import Foundation -struct GeneralService { +import Alamofire - static func judgeStatus(by statusCode: Int, _ data: Data, _ type: T.Type) -> NetworkResult { +class GeneralService { + + let AFmanager: Session = { + var requestTimeOut: Float = 30 + + var session = AF + let configuration = URLSessionConfiguration.af.default + configuration.timeoutIntervalForRequest = TimeInterval(requestTimeOut) + + session = Session(configuration: configuration) + return session + }() + + func judgeStatus(by statusCode: Int, _ data: Data, _ type: T.Type) -> NetworkResult { let decoder = JSONDecoder() guard let decodedData = try? decoder.decode(GeneralResponse.self, from: data) else { return .pathErr } diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift index b7e9ba6..7bd3405 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift @@ -8,19 +8,21 @@ import Foundation import Alamofire -struct AuthService { +class AuthService: GeneralService { static let shared = AuthService() + private override init() { } + /// [POST] 로그인 func requestSignIn(email: String, pw: String, completion: @escaping (NetworkResult) -> (Void)) { - AF.request(AuthRouter.signIn(email: email, pw: pw)) + AFmanager.request(AuthRouter.signIn(email: email, pw: pw)) .validate(statusCode: 200...500) .responseData { response in switch response.result { case .success: guard let statusCode = response.response?.statusCode else { return } guard let data = response.data else { return } - let networkResult = GeneralService.judgeStatus(by: statusCode, data, SignIn.self) + let networkResult = self.judgeStatus(by: statusCode, data, SignIn.self) completion(networkResult) @@ -31,14 +33,14 @@ struct AuthService { } /// [POST] 회원가입 func requestSignUp(email: String, name: String, pw: String, completion: @escaping (NetworkResult) -> (Void)) { - AF.request(AuthRouter.signUp(email: email, name: name, pw: pw)) + AFmanager.request(AuthRouter.signUp(email: email, name: name, pw: pw)) .validate(statusCode: 200...500) .responseData { response in switch response.result { case .success: guard let statusCode = response.response?.statusCode else { return } guard let data = response.data else { return} - let networkResult = GeneralService.judgeStatus(by: statusCode, data, SignUp.self) + let networkResult = self.judgeStatus(by: statusCode, data, SignUp.self) completion(networkResult) From 1e13cb7b7cf19920adddaec9fae82674ff588970 Mon Sep 17 00:00:00 2001 From: suyeon Date: Wed, 18 May 2022 00:18:14 +0900 Subject: [PATCH 21/30] =?UTF-8?q?[FEAT]=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CompleteLoginViewController.swift | 41 +++++++++++++++++-- .../MakePasswordViewController.swift | 1 + 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/CompleteLoginViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/CompleteLoginViewController.swift index b5099e3..9411409 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/CompleteLoginViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/CompleteLoginViewController.swift @@ -19,6 +19,7 @@ final class CompleteLoginViewController: BaseViewController { } } } + var password: String? private let titleLabel = UILabel().then { $0.text = "땡땡땡님 Instargram에 \n 오신 것을 환영합니다" @@ -38,10 +39,7 @@ final class CompleteLoginViewController: BaseViewController { private lazy var doneButton = InstaButton(title: "완료하기").then { let LoginViewAction = UIAction { _ in - let tabBarController = TabBarController() - - tabBarController.modalPresentationStyle = .fullScreen - self.present(tabBarController, animated: true) + self.postSignUp() } $0.addAction(LoginViewAction, for: .touchUpInside) } @@ -103,4 +101,39 @@ final class CompleteLoginViewController: BaseViewController { presentingVC.popToRootViewController(animated: true) self.dismiss(animated: true) } + + private func postSignUp() { + guard let name = userName, + let email = userName, + let password = password + else { return } + + AuthService.shared.requestSignUp(email: email, name: name, pw: password) { result in + switch result { + case .success: + self.makeAlert(title: "회원가입 성공") { UIAlertAction in + guard let presentingVC = self.presentingViewController as? UINavigationController else { return } + + presentingVC.popToRootViewController(animated: true) + self.dismiss(animated: true) + } + case .requestErr(let status): + guard let status = status as? Int else { return } + + switch status { + case 409: + self.makeAlert(title: "동일한 이메일로 생성된 계정이 존재합니다.") + default: + self.makeAlert(title: "아이디와 비밀번호를 확인해주세요.") + } + + case .pathErr: + print("pathErr") + case .serverErr: + print("serverErr") + case .networkFail: + print("networkFail") + } + } + } } diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakePasswordViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakePasswordViewController.swift index bb0b2c2..2153dd3 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakePasswordViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakePasswordViewController.swift @@ -43,6 +43,7 @@ final class MakePasswordViewController: BaseViewController { completeVC.modalPresentationStyle = .fullScreen completeVC.userName = self.userName + completeVC.password = self.passwordTextField.text self.present(completeVC, animated: true) } $0.addAction(completeViewAction, for: .touchUpInside) From 666e2e0d98a5a1cec99010d7a95989bb4cb1b672 Mon Sep 17 00:00:00 2001 From: suyeon Date: Thu, 19 May 2022 10:03:27 +0900 Subject: [PATCH 22/30] =?UTF-8?q?[CHORE]=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 28 ++++++++++++------- .../{ => APIConstants}/NetworkConstants.swift | 7 +++++ .../{ => APIConstants}/URLConstants.swift | 4 +++ .../Network/Foundation/APIEnvironment.swift | 4 +++ .../{NeworkRequest.swift => BaseRouter.swift} | 20 ++++++++++--- ...GeneralService.swift => BaseService.swift} | 12 +++++--- .../Network/Foundation/NetworkResult.swift | 4 +++ .../Network/Router/AuthRouter.swift | 7 ++++- .../Network/Service/AuthService.swift | 8 +++++- 9 files changed, 74 insertions(+), 20 deletions(-) rename 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/{ => APIConstants}/NetworkConstants.swift (68%) rename 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/{ => APIConstants}/URLConstants.swift (80%) rename 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/{NeworkRequest.swift => BaseRouter.swift} (75%) rename 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/{GeneralService.swift => BaseService.swift} (76%) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index 855ad40..f758156 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -13,9 +13,9 @@ 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */; }; 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */; }; 4D32E26628328DE300A3DD31 /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26528328DE300A3DD31 /* NetworkResult.swift */; }; - 4D32E26828328DF900A3DD31 /* NeworkRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26728328DF900A3DD31 /* NeworkRequest.swift */; }; + 4D32E26828328DF900A3DD31 /* BaseRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26728328DF900A3DD31 /* BaseRouter.swift */; }; 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */; }; - 4D32E26C28328E1F00A3DD31 /* GeneralService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26B28328E1F00A3DD31 /* GeneralService.swift */; }; + 4D32E26C28328E1F00A3DD31 /* BaseService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26B28328E1F00A3DD31 /* BaseService.swift */; }; 4D32E26E28328F2900A3DD31 /* GenaralResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */; }; 4D32E27028328FB400A3DD31 /* AuthRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E26F28328FB400A3DD31 /* AuthRouter.swift */; }; 4D32E27228328FC300A3DD31 /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D32E27128328FC300A3DD31 /* AuthService.swift */; }; @@ -50,9 +50,9 @@ 4D22C0CE27FB8D06005F3A73 /* CompleteLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompleteLoginViewController.swift; sourceTree = ""; }; 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIEnvironment.swift; sourceTree = ""; }; 4D32E26528328DE300A3DD31 /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = ""; }; - 4D32E26728328DF900A3DD31 /* NeworkRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeworkRequest.swift; sourceTree = ""; }; + 4D32E26728328DF900A3DD31 /* BaseRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseRouter.swift; sourceTree = ""; }; 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConstants.swift; sourceTree = ""; }; - 4D32E26B28328E1F00A3DD31 /* GeneralService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralService.swift; sourceTree = ""; }; + 4D32E26B28328E1F00A3DD31 /* BaseService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseService.swift; sourceTree = ""; }; 4D32E26D28328F2900A3DD31 /* GenaralResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenaralResponse.swift; sourceTree = ""; }; 4D32E26F28328FB400A3DD31 /* AuthRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRouter.swift; sourceTree = ""; }; 4D32E27128328FC300A3DD31 /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthService.swift; sourceTree = ""; }; @@ -93,6 +93,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4D153C9F2835C1F10072B731 /* APIConstants */ = { + isa = PBXGroup; + children = ( + 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */, + 4D32E2732832951900A3DD31 /* URLConstants.swift */, + ); + path = APIConstants; + sourceTree = ""; + }; 4D32E25E28328D1A00A3DD31 /* Network */ = { isa = PBXGroup; children = ( @@ -107,12 +116,11 @@ 4D32E25F28328D5900A3DD31 /* Foundation */ = { isa = PBXGroup; children = ( + 4D153C9F2835C1F10072B731 /* APIConstants */, 4D32E26328328DD500A3DD31 /* APIEnvironment.swift */, 4D32E26528328DE300A3DD31 /* NetworkResult.swift */, - 4D32E26728328DF900A3DD31 /* NeworkRequest.swift */, - 4D32E26928328E0E00A3DD31 /* NetworkConstants.swift */, - 4D32E26B28328E1F00A3DD31 /* GeneralService.swift */, - 4D32E2732832951900A3DD31 /* URLConstants.swift */, + 4D32E26728328DF900A3DD31 /* BaseRouter.swift */, + 4D32E26B28328E1F00A3DD31 /* BaseService.swift */, ); path = Foundation; sourceTree = ""; @@ -406,9 +414,9 @@ 4DD40B3428137ABA006CABC1 /* ShopViewController.swift in Sources */, 4D22C0CB27FB8A5E005F3A73 /* MakeNameViewController.swift in Sources */, 4DD40B3628137AC4006CABC1 /* ProfileViewController.swift in Sources */, - 4D32E26828328DF900A3DD31 /* NeworkRequest.swift in Sources */, + 4D32E26828328DF900A3DD31 /* BaseRouter.swift in Sources */, 4D32E2762832961400A3DD31 /* Auth.swift in Sources */, - 4D32E26C28328E1F00A3DD31 /* GeneralService.swift in Sources */, + 4D32E26C28328E1F00A3DD31 /* BaseService.swift in Sources */, 4DF86F5827FF72DB009DCFAA /* ImageLiteral.swift in Sources */, 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */, 4DD40B2E28137A8B006CABC1 /* FeedViewController.swift in Sources */, diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIConstants/NetworkConstants.swift similarity index 68% rename from 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift rename to 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIConstants/NetworkConstants.swift index 02fb293..16076a7 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkConstants.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIConstants/NetworkConstants.swift @@ -8,9 +8,15 @@ import Foundation import Alamofire +/* + NetworkConstants : 서버통신과정에서 필요한 상수들을 관리 -> header 관련 상수들 + */ + enum HeaderType { case basic case auth + case multiPart + case multiPartWithAuth } enum HTTPHeaderField: String { @@ -22,4 +28,5 @@ enum HTTPHeaderField: String { enum ContentType: String { case json = "Application/json" case tokenSerial = "" + case multiPart = "multipart/form-data" } diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIConstants/URLConstants.swift similarity index 80% rename from 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift rename to 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIConstants/URLConstants.swift index cd285aa..359aa4f 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/URLConstants.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIConstants/URLConstants.swift @@ -7,6 +7,10 @@ import Foundation +/* + URLConstants : 각 API 별 URL상수 관리 + */ + struct URLConstants { static let signUp = "/auth/signup" diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift index 76b96d2..851f9d2 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/APIEnvironment.swift @@ -7,6 +7,10 @@ import Foundation +/* + APIEnvironment: baseURL 및 토큰 관리, 추후 배포를 고려하여 development와 production 분리 + */ + enum APIEnvironment: String, CaseIterable { case development case production diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/BaseRouter.swift similarity index 75% rename from 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift rename to 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/BaseRouter.swift index 8a5d4f4..43fbf49 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NeworkRequest.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/BaseRouter.swift @@ -8,7 +8,12 @@ import Foundation import Alamofire -protocol Router: URLRequestConvertible { +/* + BaseRouter : URLRequestConvertible을 채택한 프로토콜, 실제 각 Endpont에 해당하는 Router들이 + BaseRouter를 채택하여 request 과정을 모듈화. + */ + +protocol BaseRouter: URLRequestConvertible { var baseURL: String { get } var method: HTTPMethod { get } var path: String { get } @@ -16,7 +21,7 @@ protocol Router: URLRequestConvertible { var header: HeaderType { get } } -extension Router { +extension BaseRouter { var baseURL: String { return APIEnvironment.development.baseUrl } @@ -28,7 +33,7 @@ extension Router { urlRequest = self.makeHeaderForRequest(to: urlRequest) - return try self.makePrameterForRequest(to: urlRequest, with: url) + return try self.makeParameterForRequest(to: urlRequest, with: url) } private func makeHeaderForRequest(to request: URLRequest) -> URLRequest { @@ -41,12 +46,19 @@ extension Router { case .auth: request.setValue(ContentType.json.rawValue, forHTTPHeaderField: HTTPHeaderField.contentType.rawValue) request.setValue(ContentType.tokenSerial.rawValue, forHTTPHeaderField: HTTPHeaderField.accesstoken.rawValue) + + case .multiPart: + request.setValue(ContentType.multiPart.rawValue, forHTTPHeaderField: HTTPHeaderField.contentType.rawValue) + + case .multiPartWithAuth: + request.setValue(ContentType.multiPart.rawValue, forHTTPHeaderField: HTTPHeaderField.contentType.rawValue) + request.setValue(ContentType.tokenSerial.rawValue, forHTTPHeaderField: HTTPHeaderField.accesstoken.rawValue) } return request } - private func makePrameterForRequest(to request: URLRequest, with url: URL) throws -> URLRequest { + private func makeParameterForRequest(to request: URLRequest, with url: URL) throws -> URLRequest { var request = request switch parameters { diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/BaseService.swift similarity index 76% rename from 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift rename to 30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/BaseService.swift index 650c0f9..c1c6d35 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/GeneralService.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/BaseService.swift @@ -9,14 +9,18 @@ import Foundation import Alamofire -class GeneralService { +class BaseService { - let AFmanager: Session = { - var requestTimeOut: Float = 30 + enum TimeOut { + static let requestTimeOut: Float = 30 + static let resourceTimeOut: Float = 30 + } + let AFmanager: Session = { var session = AF let configuration = URLSessionConfiguration.af.default - configuration.timeoutIntervalForRequest = TimeInterval(requestTimeOut) + configuration.timeoutIntervalForRequest = TimeInterval(TimeOut.requestTimeOut) + configuration.timeoutIntervalForResource = TimeInterval(TimeOut.resourceTimeOut) session = Session(configuration: configuration) return session diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkResult.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkResult.swift index 4e27907..4440064 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkResult.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Foundation/NetworkResult.swift @@ -7,6 +7,10 @@ import Foundation +/* + NetworkResult : 네트워크 결과 나누기 + */ + enum NetworkResult { case success(T) case requestErr(T) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift index de9b55f..7dec13f 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Router/AuthRouter.swift @@ -8,12 +8,17 @@ import Foundation import Alamofire +/* + AuthRouter : 여러 Endpoint들을 갖고 있는 enum + BaseRouter를 채택해서 path, method, header, parameter를 각 라우터에 맞게 request를 만든다. + */ + enum AuthRouter { case signIn(email: String, pw: String) case signUp(email: String, name: String, pw: String) } -extension AuthRouter: Router { +extension AuthRouter: BaseRouter { var path: String { switch self { diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift index 7bd3405..cd45623 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Network/Service/AuthService.swift @@ -8,7 +8,13 @@ import Foundation import Alamofire -class AuthService: GeneralService { +/* + AuthService : 실제 서버통신을 하기 위해 Service 함수를 구현하는 클래스 + 싱글턴으로 접근한다. 앞서 만든 request 함수를 호출하고 Router를 통해 서버통신 수행 + 네트워크 결과를 받아와서 + */ + +class AuthService: BaseService { static let shared = AuthService() private override init() { } From 5c69b2ae55f3941b45e25c4eb20751db382d61f1 Mon Sep 17 00:00:00 2001 From: suyeon Date: Thu, 19 May 2022 11:10:45 +0900 Subject: [PATCH 23/30] =?UTF-8?q?[ADD]=20=EC=BD=94=EB=94=94=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=A0=84=EC=B2=B4=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../30th-Assignment.xcodeproj/project.pbxproj | 56 +++++++++++++++++++ .../Screens/Coordinator/AppCoordinator.swift | 8 +++ .../AuthCoordinators/LoginCoordinator.swift | 8 +++ .../AuthCoordinators/SignUpCoordinator.swift | 8 +++ .../Coordinator/Foundation/Coordinator.swift | 8 +++ .../Foundation/TransitionModel.swift | 8 +++ .../TabBarCoordinators/FeedCoordinator.swift | 8 +++ 7 files changed, 104 insertions(+) create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AppCoordinator.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/LoginCoordinator.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/SignUpCoordinator.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/Coordinator.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/TransitionModel.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/TabBarCoordinators/FeedCoordinator.swift diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index f758156..308e592 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -7,6 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 4D153CA32835DA150072B731 /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CA22835DA150072B731 /* AppCoordinator.swift */; }; + 4D153CA52835DA290072B731 /* LoginCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CA42835DA290072B731 /* LoginCoordinator.swift */; }; + 4D153CA72835DA570072B731 /* FeedCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CA62835DA570072B731 /* FeedCoordinator.swift */; }; + 4D153CA92835DDB80072B731 /* SignUpCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CA82835DDB80072B731 /* SignUpCoordinator.swift */; }; + 4D153CAD2835DE570072B731 /* Coordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CAC2835DE570072B731 /* Coordinator.swift */; }; + 4D153CAF2835DE750072B731 /* TransitionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CAE2835DE750072B731 /* TransitionModel.swift */; }; 4D22C0C927FB74FD005F3A73 /* InstaButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0C827FB74FD005F3A73 /* InstaButton.swift */; }; 4D22C0CB27FB8A5E005F3A73 /* MakeNameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CA27FB8A5E005F3A73 /* MakeNameViewController.swift */; }; 4D22C0CD27FB8C6C005F3A73 /* MakePasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */; }; @@ -44,6 +50,12 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 4D153CA22835DA150072B731 /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; + 4D153CA42835DA290072B731 /* LoginCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginCoordinator.swift; sourceTree = ""; }; + 4D153CA62835DA570072B731 /* FeedCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedCoordinator.swift; sourceTree = ""; }; + 4D153CA82835DDB80072B731 /* SignUpCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpCoordinator.swift; sourceTree = ""; }; + 4D153CAC2835DE570072B731 /* Coordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Coordinator.swift; sourceTree = ""; }; + 4D153CAE2835DE750072B731 /* TransitionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransitionModel.swift; sourceTree = ""; }; 4D22C0C827FB74FD005F3A73 /* InstaButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstaButton.swift; sourceTree = ""; }; 4D22C0CA27FB8A5E005F3A73 /* MakeNameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeNameViewController.swift; sourceTree = ""; }; 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakePasswordViewController.swift; sourceTree = ""; }; @@ -102,6 +114,43 @@ path = APIConstants; sourceTree = ""; }; + 4D153CA02835D9870072B731 /* Coordinator */ = { + isa = PBXGroup; + children = ( + 4D153CA22835DA150072B731 /* AppCoordinator.swift */, + 4D153CA12835DA000072B731 /* Foundation */, + 4D153CAA2835DDBF0072B731 /* AuthCoordinators */, + 4D153CAB2835DDEA0072B731 /* TabBarCoordinators */, + ); + path = Coordinator; + sourceTree = ""; + }; + 4D153CA12835DA000072B731 /* Foundation */ = { + isa = PBXGroup; + children = ( + 4D153CAC2835DE570072B731 /* Coordinator.swift */, + 4D153CAE2835DE750072B731 /* TransitionModel.swift */, + ); + path = Foundation; + sourceTree = ""; + }; + 4D153CAA2835DDBF0072B731 /* AuthCoordinators */ = { + isa = PBXGroup; + children = ( + 4D153CA42835DA290072B731 /* LoginCoordinator.swift */, + 4D153CA82835DDB80072B731 /* SignUpCoordinator.swift */, + ); + path = AuthCoordinators; + sourceTree = ""; + }; + 4D153CAB2835DDEA0072B731 /* TabBarCoordinators */ = { + isa = PBXGroup; + children = ( + 4D153CA62835DA570072B731 /* FeedCoordinator.swift */, + ); + path = TabBarCoordinators; + sourceTree = ""; + }; 4D32E25E28328D1A00A3DD31 /* Network */ = { isa = PBXGroup; children = ( @@ -241,6 +290,7 @@ 4DD4DBA827FA17F200E54124 /* Screens */ = { isa = PBXGroup; children = ( + 4D153CA02835D9870072B731 /* Coordinator */, 4DD40B24281379AB006CABC1 /* Tabbar */, 4DD40B2C28137A6D006CABC1 /* Feed */, 4DD40B2B28137A65006CABC1 /* Search */, @@ -407,17 +457,22 @@ 4DD40B3028137A9A006CABC1 /* SearchViewController.swift in Sources */, 4D32E26E28328F2900A3DD31 /* GenaralResponse.swift in Sources */, 4DD4DBBF27FA43AC00E54124 /* UIView+.swift in Sources */, + 4D153CAF2835DE750072B731 /* TransitionModel.swift in Sources */, 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */, 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */, 4D22C0C927FB74FD005F3A73 /* InstaButton.swift in Sources */, 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */, 4DD40B3428137ABA006CABC1 /* ShopViewController.swift in Sources */, + 4D153CA72835DA570072B731 /* FeedCoordinator.swift in Sources */, 4D22C0CB27FB8A5E005F3A73 /* MakeNameViewController.swift in Sources */, + 4D153CAD2835DE570072B731 /* Coordinator.swift in Sources */, 4DD40B3628137AC4006CABC1 /* ProfileViewController.swift in Sources */, 4D32E26828328DF900A3DD31 /* BaseRouter.swift in Sources */, 4D32E2762832961400A3DD31 /* Auth.swift in Sources */, + 4D153CA32835DA150072B731 /* AppCoordinator.swift in Sources */, 4D32E26C28328E1F00A3DD31 /* BaseService.swift in Sources */, 4DF86F5827FF72DB009DCFAA /* ImageLiteral.swift in Sources */, + 4D153CA52835DA290072B731 /* LoginCoordinator.swift in Sources */, 4D22C0CF27FB8D06005F3A73 /* CompleteLoginViewController.swift in Sources */, 4DD40B2E28137A8B006CABC1 /* FeedViewController.swift in Sources */, 4D32E26628328DE300A3DD31 /* NetworkResult.swift in Sources */, @@ -430,6 +485,7 @@ 4DD4DB9427FA171D00E54124 /* AppDelegate.swift in Sources */, 4D32E27E2832B25500A3DD31 /* UIViewController+.swift in Sources */, 4D32E27028328FB400A3DD31 /* AuthRouter.swift in Sources */, + 4D153CA92835DDB80072B731 /* SignUpCoordinator.swift in Sources */, 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */, 4DD40B3228137AAD006CABC1 /* ReelsViewController.swift in Sources */, 4DD4DB9627FA171D00E54124 /* SceneDelegate.swift in Sources */, diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AppCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AppCoordinator.swift new file mode 100644 index 0000000..1df0497 --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AppCoordinator.swift @@ -0,0 +1,8 @@ +// +// AppCoordinator.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/19. +// + +import Foundation diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/LoginCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/LoginCoordinator.swift new file mode 100644 index 0000000..a60529e --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/LoginCoordinator.swift @@ -0,0 +1,8 @@ +// +// LoginCoordinator.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/19. +// + +import Foundation diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/SignUpCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/SignUpCoordinator.swift new file mode 100644 index 0000000..6fbd18e --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/SignUpCoordinator.swift @@ -0,0 +1,8 @@ +// +// SignUpCoordinator.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/19. +// + +import Foundation diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/Coordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/Coordinator.swift new file mode 100644 index 0000000..118366b --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/Coordinator.swift @@ -0,0 +1,8 @@ +// +// Coordinator.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/19. +// + +import Foundation diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/TransitionModel.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/TransitionModel.swift new file mode 100644 index 0000000..74e782f --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/TransitionModel.swift @@ -0,0 +1,8 @@ +// +// TransitionModel.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/19. +// + +import Foundation diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/TabBarCoordinators/FeedCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/TabBarCoordinators/FeedCoordinator.swift new file mode 100644 index 0000000..952ffaa --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/TabBarCoordinators/FeedCoordinator.swift @@ -0,0 +1,8 @@ +// +// FeedCoordinator.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/19. +// + +import Foundation From 94b46239b3c674e60ade2543c221bf7cd75a02a1 Mon Sep 17 00:00:00 2001 From: suyeon Date: Sat, 21 May 2022 09:51:14 +0900 Subject: [PATCH 24/30] =?UTF-8?q?[CHORE]=20=ED=83=AD=EB=B0=94=20=EC=9E=A0?= =?UTF-8?q?=EC=8B=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Screens/Tabbar/TabBarController.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Tabbar/TabBarController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Tabbar/TabBarController.swift index 603d457..cef026b 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Tabbar/TabBarController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Tabbar/TabBarController.swift @@ -27,12 +27,12 @@ final class TabBarController: UITabBarController { } private func makeTabBarItems() { - let feedVC = FeedViewController() - feedVC.tabBarItem = UITabBarItem( - title: "", - image: ImageLiteral.iconHome, - selectedImage: ImageLiteral.iconHomeSelected - ) +// let feedVC = FeedViewController(coordinator: FeedCoordinator) +// feedVC.tabBarItem = UITabBarItem( +// title: "", +// image: ImageLiteral.iconHome, +// selectedImage: ImageLiteral.iconHomeSelected +// ) let searchVC = SearchViewController() searchVC.tabBarItem = UITabBarItem( @@ -64,7 +64,7 @@ final class TabBarController: UITabBarController { ) let tabBarViewControllers: [UIViewController] = { - let tabBarViewControllers = [feedVC, + let tabBarViewControllers = [ searchVC, reelsVC, shopVC, From fb04b0a3c2f836e070aa908ac0416caa31ea5ad0 Mon Sep 17 00:00:00 2001 From: suyeon Date: Sat, 21 May 2022 09:51:59 +0900 Subject: [PATCH 25/30] =?UTF-8?q?[FEAT]=20=20SceneDelegate=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Global/Supports/SceneDelegate.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Global/Supports/SceneDelegate.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Global/Supports/SceneDelegate.swift index f9aa757..390fe2d 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Global/Supports/SceneDelegate.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Global/Supports/SceneDelegate.swift @@ -13,15 +13,22 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { - guard let windowScene = (scene as? UIWindowScene) else { return } +// guard let windowScene = (scene as? UIWindowScene) else { return } +// +// let rootViewController = LoginViewController() +// let navigationController = UINavigationController(rootViewController: rootViewController) +// let window = UIWindow(windowScene: windowScene) +// window.rootViewController = navigationController +// self.window = window +// window.backgroundColor = .white +// window.makeKeyAndVisible() - let rootViewController = LoginViewController() - let navigationController = UINavigationController(rootViewController: rootViewController) + guard let windowScene = (scene as? UIWindowScene) else { return } let window = UIWindow(windowScene: windowScene) - window.rootViewController = navigationController self.window = window - window.backgroundColor = .white - window.makeKeyAndVisible() + + let coordinator = AppCoordinator(window: window) + coordinator.start() } func sceneDidDisconnect(_ scene: UIScene) { From a626e15842240f9e79c2918c97435ddf61d7ba78 Mon Sep 17 00:00:00 2001 From: suyeon Date: Sat, 21 May 2022 09:52:32 +0900 Subject: [PATCH 26/30] =?UTF-8?q?[FEAT]=20Appcoordinator=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Screens/Coordinator/AppCoordinator.swift | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AppCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AppCoordinator.swift index 1df0497..279af3f 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AppCoordinator.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AppCoordinator.swift @@ -6,3 +6,46 @@ // import Foundation +import UIKit + +final class AppCoordinator: Coordinator { + var presenter: UINavigationController + var childCoordinators: [Coordinator] = [] + weak var parentCoordinator: Coordinator? + var window: UIWindow + + // Appcoordinator 초기화 과정 + init(window: UIWindow) { + self.window = window + presenter = UINavigationController() + window.backgroundColor = .white + window.makeKeyAndVisible() + } + + func start() { + /// 자식 코디네이터 초기화 해주고, root를 탭바 컨트롤러로 ! + // removeChildCoordinators() + transitionToLogin() + } + + func transitionToTabbarController() -> UITabBarController { + // 탭바컨트롤러로 전환하면서 생성해주기 !! + let tabBarController = UITabBarController() + + let feedCoordinator = FeedCoordinator(presenter: UINavigationController()) + feedCoordinator.start() + + tabBarController.viewControllers = [ + feedCoordinator.presenter + ] + + return tabBarController + } + + func transitionToLogin() { + let childCoordinator = LoginCoordinator(presenter: presenter) + childCoordinator.parentCoordinator = self + addChildCoordinator(childCoordinator) + childCoordinator.start() + } +} From eebe8b4ceb2345cd7b5cacb8ca1153a97dc847e0 Mon Sep 17 00:00:00 2001 From: suyeon Date: Sat, 21 May 2022 09:52:56 +0900 Subject: [PATCH 27/30] =?UTF-8?q?[FEAT]=20=EC=BD=94=EB=94=94=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=ED=94=84=EB=A1=9C=ED=86=A0=EC=BD=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Coordinator/Foundation/Coordinator.swift | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/Coordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/Coordinator.swift index 118366b..85855ea 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/Coordinator.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/Coordinator.swift @@ -6,3 +6,81 @@ // import Foundation +import UIKit + +protocol Coordinator: AnyObject { + // 코디네이터가 화면 전환을 위해 가지고 있는 네비게이션 컨트롤러 ! + var presenter: UINavigationController { get set } + // 자식 코디네이터들을 담을 배열 + var childCoordinators: [Coordinator] { get set } + // 자식 코디네이터들을 생성하고 제거하는 부모코디네이터 + var parentCoordinator: Coordinator? { get set } +} + +extension Coordinator { + + // 화면 전환스타일에 따라 구현해놓은 메서드 + func transition(to coordinator: Coordinator, + with viewController: UIViewController, + using style: TransitionStyle, + animated: Bool = false, + completion: (() -> Void)? = nil) { + + switch style { + case .root: + // root를 재설정해주고 이동하는 transition + presenter = UINavigationController(rootViewController: viewController) + let scene = UIApplication.shared.connectedScenes.first + if let sceneDelegate: SceneDelegate = scene?.delegate as? SceneDelegate { + sceneDelegate.window?.rootViewController = presenter + } + // 음 어떤 코디네이터로 root설정을 하므로 돌아가므로 원래 자식 코디네이터들 전부 삭제 ~ + removeChildCoordinators() + // 돌아간 코디네이터를 자식 코디네이터에 추가 - 이건 잘 모르겠음 + addChildCoordinator(coordinator) + case .push: + // push해서 이동할 코디네이터를 자식코디네이터로 추가 + addChildCoordinator(coordinator) + // navigation push + presenter.pushViewController(viewController, animated: animated) + case .modal: + // present할 코디네이터를 자식 코디네이터로 추가 + addChildCoordinator(coordinator) + // present ! + presenter.present(viewController, animated: animated, completion: completion) + } + } + + /// 자식 코디네이터가 할일을 끝냈을 때 호출 + /// : 자신의 부모코디네이터에 접근해서 자기 자신을 자식코디네이터 배열에서 지워줌 + /// 보통 viewDidDisappear 에서 호출 ! 화면이 사라질 시점 ! + /// or NavigationController Delegate의 didShow() 메서드에서 호출 + func didFinishChildCoordinator() { + parentCoordinator?.removeChildCoordinator(self) + } + + // 자식 코디네이터를 추가하는 메서드 : 부모에서 이동할 코디네이터를 자식으로 추가해서 관리 ! + func addChildCoordinator(_ childCoordinator: Coordinator) { + self.childCoordinators.append(childCoordinator) + } + + /// 자식 코디네이터를 지우는 메서드 + /// 예를 들어 어떤 VC에서 첫화면으로 돌아간다면 ? parent coordinator한테 알린다음에 + /// childcoordinator 배열에서 VC들을 지워야합니다 + /// 위에 보면 didFinsh ~ 메서드 내부에서 호출해주는데 , 부모 코디네이터에 접근해서 자식을 지워줍니다 ~~ + func removeChildCoordinator(_ childCoordinator: Coordinator) { + /// === 는 클래스의 두 인스턴스가 동일한 메모리를 가리키는지 점검하는 연산자 이므로 + /// 코디네이터 프로토콜을 클래스 전용 프로토콜로 만들자 !! + /// 내가 이해한 바로는 받은 파라미터로 받은 childCoordinator랑 동일 메모리를 가지는 그 코디네이터를 찾아서 + /// 인덱스를 반환해주는것 같다 ! + if let index = childCoordinators.firstIndex(where: { $0 === childCoordinator }) { + childCoordinators.remove(at: index) + } + } + + func removeChildCoordinators() { + /// 따로 파라미터를 받는게 아니라 전부 삭제 + childCoordinators.forEach { $0.removeChildCoordinators() } + childCoordinators.removeAll() + } +} From 0beb13e386925ed8507a00d6b282e3ca2012e8b3 Mon Sep 17 00:00:00 2001 From: suyeon Date: Sat, 21 May 2022 09:53:58 +0900 Subject: [PATCH 28/30] =?UTF-8?q?[FEAT]=20=ED=99=94=EB=A9=B4=EC=A0=84?= =?UTF-8?q?=ED=99=98=ED=95=A0=20=EC=BD=94=EB=94=94=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EB=93=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 커밋나누기 제법 귀춘네.. --- .../30th-Assignment.xcodeproj/project.pbxproj | 16 ++++++--- .../CompleteLoginCoordinator.swift | 33 +++++++++++++++++++ .../AuthCoordinators/LoginCoordinator.swift | 32 ++++++++++++++++++ .../MakeNameCoordinator.swift | 32 ++++++++++++++++++ .../MakePasswordCoordinator.swift | 33 +++++++++++++++++++ .../AuthCoordinators/SignUpCoordinator.swift | 8 ----- .../TabBarCoordinators/FeedCoordinator.swift | 18 ++++++++++ 7 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/CompleteLoginCoordinator.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/MakeNameCoordinator.swift create mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/MakePasswordCoordinator.swift delete mode 100644 30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/SignUpCoordinator.swift diff --git a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj index 308e592..6a45e6c 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj +++ b/30th-Assignment/30th-Assignment/30th-Assignment.xcodeproj/project.pbxproj @@ -10,9 +10,11 @@ 4D153CA32835DA150072B731 /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CA22835DA150072B731 /* AppCoordinator.swift */; }; 4D153CA52835DA290072B731 /* LoginCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CA42835DA290072B731 /* LoginCoordinator.swift */; }; 4D153CA72835DA570072B731 /* FeedCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CA62835DA570072B731 /* FeedCoordinator.swift */; }; - 4D153CA92835DDB80072B731 /* SignUpCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CA82835DDB80072B731 /* SignUpCoordinator.swift */; }; + 4D153CA92835DDB80072B731 /* MakeNameCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CA82835DDB80072B731 /* MakeNameCoordinator.swift */; }; 4D153CAD2835DE570072B731 /* Coordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CAC2835DE570072B731 /* Coordinator.swift */; }; 4D153CAF2835DE750072B731 /* TransitionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CAE2835DE750072B731 /* TransitionModel.swift */; }; + 4D153CB1283665460072B731 /* MakePasswordCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CB0283665460072B731 /* MakePasswordCoordinator.swift */; }; + 4D153CB32836694E0072B731 /* CompleteLoginCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D153CB22836694E0072B731 /* CompleteLoginCoordinator.swift */; }; 4D22C0C927FB74FD005F3A73 /* InstaButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0C827FB74FD005F3A73 /* InstaButton.swift */; }; 4D22C0CB27FB8A5E005F3A73 /* MakeNameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CA27FB8A5E005F3A73 /* MakeNameViewController.swift */; }; 4D22C0CD27FB8C6C005F3A73 /* MakePasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */; }; @@ -53,9 +55,11 @@ 4D153CA22835DA150072B731 /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 4D153CA42835DA290072B731 /* LoginCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginCoordinator.swift; sourceTree = ""; }; 4D153CA62835DA570072B731 /* FeedCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedCoordinator.swift; sourceTree = ""; }; - 4D153CA82835DDB80072B731 /* SignUpCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpCoordinator.swift; sourceTree = ""; }; + 4D153CA82835DDB80072B731 /* MakeNameCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeNameCoordinator.swift; sourceTree = ""; }; 4D153CAC2835DE570072B731 /* Coordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Coordinator.swift; sourceTree = ""; }; 4D153CAE2835DE750072B731 /* TransitionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransitionModel.swift; sourceTree = ""; }; + 4D153CB0283665460072B731 /* MakePasswordCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakePasswordCoordinator.swift; sourceTree = ""; }; + 4D153CB22836694E0072B731 /* CompleteLoginCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompleteLoginCoordinator.swift; sourceTree = ""; }; 4D22C0C827FB74FD005F3A73 /* InstaButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstaButton.swift; sourceTree = ""; }; 4D22C0CA27FB8A5E005F3A73 /* MakeNameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeNameViewController.swift; sourceTree = ""; }; 4D22C0CC27FB8C6C005F3A73 /* MakePasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakePasswordViewController.swift; sourceTree = ""; }; @@ -138,7 +142,9 @@ isa = PBXGroup; children = ( 4D153CA42835DA290072B731 /* LoginCoordinator.swift */, - 4D153CA82835DDB80072B731 /* SignUpCoordinator.swift */, + 4D153CA82835DDB80072B731 /* MakeNameCoordinator.swift */, + 4D153CB0283665460072B731 /* MakePasswordCoordinator.swift */, + 4D153CB22836694E0072B731 /* CompleteLoginCoordinator.swift */, ); path = AuthCoordinators; sourceTree = ""; @@ -459,11 +465,13 @@ 4DD4DBBF27FA43AC00E54124 /* UIView+.swift in Sources */, 4D153CAF2835DE750072B731 /* TransitionModel.swift in Sources */, 4D32E26A28328E0E00A3DD31 /* NetworkConstants.swift in Sources */, + 4D153CB1283665460072B731 /* MakePasswordCoordinator.swift in Sources */, 4DD40B26281379D7006CABC1 /* TabBarController.swift in Sources */, 4D22C0C927FB74FD005F3A73 /* InstaButton.swift in Sources */, 4D32E26428328DD500A3DD31 /* APIEnvironment.swift in Sources */, 4DD40B3428137ABA006CABC1 /* ShopViewController.swift in Sources */, 4D153CA72835DA570072B731 /* FeedCoordinator.swift in Sources */, + 4D153CB32836694E0072B731 /* CompleteLoginCoordinator.swift in Sources */, 4D22C0CB27FB8A5E005F3A73 /* MakeNameViewController.swift in Sources */, 4D153CAD2835DE570072B731 /* Coordinator.swift in Sources */, 4DD40B3628137AC4006CABC1 /* ProfileViewController.swift in Sources */, @@ -485,7 +493,7 @@ 4DD4DB9427FA171D00E54124 /* AppDelegate.swift in Sources */, 4D32E27E2832B25500A3DD31 /* UIViewController+.swift in Sources */, 4D32E27028328FB400A3DD31 /* AuthRouter.swift in Sources */, - 4D153CA92835DDB80072B731 /* SignUpCoordinator.swift in Sources */, + 4D153CA92835DDB80072B731 /* MakeNameCoordinator.swift in Sources */, 4D32E2742832951900A3DD31 /* URLConstants.swift in Sources */, 4DD40B3228137AAD006CABC1 /* ReelsViewController.swift in Sources */, 4DD4DB9627FA171D00E54124 /* SceneDelegate.swift in Sources */, diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/CompleteLoginCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/CompleteLoginCoordinator.swift new file mode 100644 index 0000000..ac754a1 --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/CompleteLoginCoordinator.swift @@ -0,0 +1,33 @@ +// +// CompleteLoginCoordinator.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/19. +// + +import Foundation +import UIKit + +final class CompleteLoginCoordinator: Coordinator { + + var presenter: UINavigationController + var childCoordinators: [Coordinator] = [] + weak var parentCoordinator: Coordinator? + + init(presenter: UINavigationController) { + self.presenter = presenter + } + + func start(userName: String, password: String) { + let completeLoginViewController = CompleteLoginViewController(coordinator: self) + completeLoginViewController.userName = userName + completeLoginViewController.password = password + completeLoginViewController.modalPresentationStyle = .fullScreen + transition(to: self, with: completeLoginViewController, using: .modal, animated: true) + } + + func transitionToLogin() { + let loginCoordinator = LoginCoordinator(presenter: presenter) + loginCoordinator.start() + } +} diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/LoginCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/LoginCoordinator.swift index a60529e..5a946d2 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/LoginCoordinator.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/LoginCoordinator.swift @@ -6,3 +6,35 @@ // import Foundation +import UIKit + +final class LoginCoordinator: Coordinator { + + var presenter: UINavigationController + var childCoordinators: [Coordinator] = [] + weak var parentCoordinator: Coordinator? + + init(presenter: UINavigationController) { + self.presenter = presenter + } + + func start() { + let loginViewController = LoginViewController(coordinator: self) + transition(to: self, with: loginViewController, using: .root) + // presenter.setViewControllers([loginViewController], animated: false) + } + + func transitionToMakeName() { + let childCoordinator = MakeNameCoordinator(presenter: presenter) + childCoordinator.parentCoordinator = self + addChildCoordinator(childCoordinator) + childCoordinator.start() + } + + func transitionToFeed() { + let feedCoordinator = FeedCoordinator(presenter: presenter) + feedCoordinator.start() + // transition(to: feedCoordinator, with: FeedViewController(coordinator: feedCoordinator), using: .root) + } +} + diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/MakeNameCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/MakeNameCoordinator.swift new file mode 100644 index 0000000..9fb3f40 --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/MakeNameCoordinator.swift @@ -0,0 +1,32 @@ +// +// SignUpCoordinator.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/19. +// + +import Foundation +import UIKit + +final class MakeNameCoordinator: Coordinator { + + var presenter: UINavigationController + var childCoordinators: [Coordinator] = [] + weak var parentCoordinator: Coordinator? + + init(presenter: UINavigationController) { + self.presenter = presenter + } + + func start() { + let makeNameViewController = MakeNameViewController(coordinator: self) + presenter.setViewControllers([makeNameViewController], animated: true) + } + + func transitionToMakePassword(userName: String) { + let childCoordinator = MakePasswordCoordinator(presenter: presenter) + childCoordinator.parentCoordinator = self + addChildCoordinator(childCoordinator) + childCoordinator.start(userName: userName) + } +} diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/MakePasswordCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/MakePasswordCoordinator.swift new file mode 100644 index 0000000..b2e611a --- /dev/null +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/MakePasswordCoordinator.swift @@ -0,0 +1,33 @@ +// +// MakePasswordCoordinator.swift +// 30th-Assignment +// +// Created by 김수연 on 2022/05/19. +// + +import Foundation +import UIKit + +final class MakePasswordCoordinator: Coordinator { + + var presenter: UINavigationController + var childCoordinators: [Coordinator] = [] + weak var parentCoordinator: Coordinator? + + init(presenter: UINavigationController) { + self.presenter = presenter + } + + func start(userName: String) { + let makePasswordViewController = MakePasswordViewController(coordinator: self) + makePasswordViewController.userName = userName + transition(to: self, with: makePasswordViewController, using: .push, animated: true) + } + + func transitionToComplete(userName: String, password: String) { + let childCoordinator = CompleteLoginCoordinator(presenter: presenter) + childCoordinator.parentCoordinator = self + addChildCoordinator(childCoordinator) + childCoordinator.start(userName: userName, password: password) + } +} diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/SignUpCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/SignUpCoordinator.swift deleted file mode 100644 index 6fbd18e..0000000 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/AuthCoordinators/SignUpCoordinator.swift +++ /dev/null @@ -1,8 +0,0 @@ -// -// SignUpCoordinator.swift -// 30th-Assignment -// -// Created by 김수연 on 2022/05/19. -// - -import Foundation diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/TabBarCoordinators/FeedCoordinator.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/TabBarCoordinators/FeedCoordinator.swift index 952ffaa..1ee2440 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/TabBarCoordinators/FeedCoordinator.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/TabBarCoordinators/FeedCoordinator.swift @@ -6,3 +6,21 @@ // import Foundation +import UIKit + +final class FeedCoordinator: Coordinator { + + var presenter: UINavigationController + var childCoordinators: [Coordinator] = [] + weak var parentCoordinator: Coordinator? + + init(presenter: UINavigationController) { + self.presenter = presenter + } + + func start() { + let feedViewController = FeedViewController(coordinator: self) + feedViewController.tabBarItem = UITabBarItem(title: "", image: ImageLiteral.iconHome,selectedImage: ImageLiteral.iconHomeSelected) + presenter.setViewControllers([feedViewController], animated: false) + } +} From 7bf6e68de4c5686420dcb29fb971691d540ac52e Mon Sep 17 00:00:00 2001 From: suyeon Date: Sat, 21 May 2022 09:54:13 +0900 Subject: [PATCH 29/30] =?UTF-8?q?[FEAT]=20Transition=20Model=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Coordinator/Foundation/TransitionModel.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/TransitionModel.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/TransitionModel.swift index 74e782f..68ac181 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/TransitionModel.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Coordinator/Foundation/TransitionModel.swift @@ -6,3 +6,17 @@ // import Foundation + +/// 화면전환 스타일 enum + +enum TransitionStyle { + case root + case push + case modal +} + +enum TransitionError { + case navigationControllerMissing + case cannotPop + case unknown +} From 4e7bf5701dec0fe02370c9d07869cbd34467f71c Mon Sep 17 00:00:00 2001 From: suyeon Date: Sat, 21 May 2022 09:54:33 +0900 Subject: [PATCH 30/30] =?UTF-8?q?[FEAT]=20=EC=BD=94=EB=94=94=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=EB=A1=9C=20=ED=99=94=EB=A9=B4=EC=A0=84?= =?UTF-8?q?=ED=99=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CompleteLoginViewController.swift | 23 +++++++++++++++---- .../Authentication/LoginViewController.swift | 22 ++++++++++++++++-- .../MakeNameViewController.swift | 21 +++++++++++++---- .../MakePasswordViewController.swift | 22 +++++++++++++----- .../Screens/Feed/FeedViewController.swift | 16 +++++++++++++ 5 files changed, 88 insertions(+), 16 deletions(-) diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/CompleteLoginViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/CompleteLoginViewController.swift index 9411409..eb483da 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/CompleteLoginViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/CompleteLoginViewController.swift @@ -12,6 +12,8 @@ import Then final class CompleteLoginViewController: BaseViewController { + private var coordinator: CompleteLoginCoordinator + var userName: String? { didSet { if let userName = userName { @@ -51,10 +53,24 @@ final class CompleteLoginViewController: BaseViewController { $0.font = .systemFont(ofSize: 14, weight: .regular) } + init(coordinator: CompleteLoginCoordinator) { + self.coordinator = coordinator + super.init() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func viewDidLoad() { super.viewDidLoad() } + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + coordinator.didFinishChildCoordinator() + } + override func configUI() { view.backgroundColor = .white setupBaseNavigationBar() @@ -112,10 +128,9 @@ final class CompleteLoginViewController: BaseViewController { switch result { case .success: self.makeAlert(title: "회원가입 성공") { UIAlertAction in - guard let presentingVC = self.presentingViewController as? UINavigationController else { return } - - presentingVC.popToRootViewController(animated: true) - self.dismiss(animated: true) + self.dismiss(animated: true) { + self.coordinator.transitionToLogin() + } } case .requestErr(let status): guard let status = status as? Int else { return } diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift index 6efa4d4..f13769e 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/LoginViewController.swift @@ -12,6 +12,8 @@ import Then final class LoginViewController: BaseViewController { + private var coordinator: LoginCoordinator + private let logoImage = UIImageView().then { $0.image = ImageLiteral.imgInstagramLogo $0.contentMode = .scaleToFill @@ -56,11 +58,20 @@ final class LoginViewController: BaseViewController { $0.titleLabel?.font = .systemFont(ofSize: 14) let pushSignUpViewAction = UIAction { _ in - self.navigationController?.pushViewController(MakeNameViewController(), animated: true) + self.coordinator.transitionToMakeName() } $0.addAction(pushSignUpViewAction, for: .touchUpInside) } + init(coordinator: LoginCoordinator) { + self.coordinator = coordinator + super.init() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func viewDidLoad() { super.viewDidLoad() } @@ -70,6 +81,11 @@ final class LoginViewController: BaseViewController { intialize() } + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + coordinator.didFinishChildCoordinator() + } + /// 화면 터치했을 때 텍스트 필드 edit 종료하기 override func touchesBegan(_ touches: Set, with event: UIEvent?) { view.endEditing(true) @@ -148,7 +164,9 @@ final class LoginViewController: BaseViewController { AuthService.shared.requestSignIn(email: email, pw: password) { result in switch result { case .success: - self.makePresentAlert(title: "로그인 성공", nextVC: TabBarController()) + self.makeAlert(title: "로그인성공") { _ in + self.coordinator.transitionToFeed() + } case .requestErr(let status): guard let status = status as? Int else { return } diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakeNameViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakeNameViewController.swift index cb2c2d7..b744e78 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakeNameViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakeNameViewController.swift @@ -12,6 +12,8 @@ import Then final class MakeNameViewController: BaseViewController { + private var coordinator: MakeNameCoordinator + private let titleLabel = UILabel().then { $0.text = "사용자 이름 만들기" $0.font = .systemFont(ofSize: 24) @@ -36,14 +38,20 @@ final class MakeNameViewController: BaseViewController { $0.isEnabled = false let pushMakePasswordViewAction = UIAction { _ in - let makePasswordVC = MakePasswordViewController() - - makePasswordVC.userName = self.userNameTextField.text ?? "" - self.navigationController?.pushViewController(makePasswordVC, animated: true) + self.coordinator.transitionToMakePassword(userName: self.userNameTextField.text ?? "") } $0.addAction(pushMakePasswordViewAction, for: .touchUpInside) } + init(coordinator: MakeNameCoordinator) { + self.coordinator = coordinator + super.init() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func viewDidLoad() { super.viewDidLoad() } @@ -52,6 +60,11 @@ final class MakeNameViewController: BaseViewController { view.endEditing(true) } + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + coordinator.didFinishChildCoordinator() + } + override func configUI() { view.backgroundColor = .white setupBaseNavigationBar() diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakePasswordViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakePasswordViewController.swift index 2153dd3..337d3c6 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakePasswordViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Authentication/MakePasswordViewController.swift @@ -13,6 +13,7 @@ import Then final class MakePasswordViewController: BaseViewController { var userName: String? + private var coordinator: MakePasswordCoordinator private let titleLabel = UILabel().then { $0.text = "비밀번호 만들기" @@ -39,20 +40,29 @@ final class MakePasswordViewController: BaseViewController { $0.isEnabled = false let completeViewAction = UIAction { _ in - let completeVC = CompleteLoginViewController() - - completeVC.modalPresentationStyle = .fullScreen - completeVC.userName = self.userName - completeVC.password = self.passwordTextField.text - self.present(completeVC, animated: true) + self.coordinator.transitionToComplete(userName: self.userName ?? "", password: self.passwordTextField.text ?? "") } $0.addAction(completeViewAction, for: .touchUpInside) } + init(coordinator: MakePasswordCoordinator) { + self.coordinator = coordinator + super.init() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func viewDidLoad() { super.viewDidLoad() } + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + coordinator.didFinishChildCoordinator() + } + override func touchesBegan(_ touches: Set, with event: UIEvent?) { view.endEditing(true) } diff --git a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Feed/FeedViewController.swift b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Feed/FeedViewController.swift index e94d8c9..0434172 100644 --- a/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Feed/FeedViewController.swift +++ b/30th-Assignment/30th-Assignment/30th-Assignment/Screens/Feed/FeedViewController.swift @@ -9,10 +9,26 @@ import UIKit class FeedViewController: BaseViewController { + private var coordinator: FeedCoordinator + + init(coordinator: FeedCoordinator) { + self.coordinator = coordinator + super.init() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func viewDidLoad() { super.viewDidLoad() } + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + coordinator.didFinishChildCoordinator() + } + override func configUI() { view.backgroundColor = .blue }