From ad9724e34ef1f16227c141ddc4272aaedaf131ba Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Mon, 7 Feb 2022 02:59:20 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[Chore]=20AuthAPI=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Auth에 사용되는 API와 Service 폴더 정리 --- Hyangyu/Hyangyu/Sources/APIServices/{ => AuthAPI}/LoginAPI.swift | 0 .../Hyangyu/Sources/APIServices/{ => AuthAPI}/LoginService.swift | 0 .../Hyangyu/Sources/APIServices/{ => AuthAPI}/PasswordAPI.swift | 0 .../Sources/APIServices/{ => AuthAPI}/PasswordService.swift | 0 Hyangyu/Hyangyu/Sources/APIServices/{ => AuthAPI}/SignUpAPI.swift | 0 .../Hyangyu/Sources/APIServices/{ => AuthAPI}/SignUpService.swift | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename Hyangyu/Hyangyu/Sources/APIServices/{ => AuthAPI}/LoginAPI.swift (100%) rename Hyangyu/Hyangyu/Sources/APIServices/{ => AuthAPI}/LoginService.swift (100%) rename Hyangyu/Hyangyu/Sources/APIServices/{ => AuthAPI}/PasswordAPI.swift (100%) rename Hyangyu/Hyangyu/Sources/APIServices/{ => AuthAPI}/PasswordService.swift (100%) rename Hyangyu/Hyangyu/Sources/APIServices/{ => AuthAPI}/SignUpAPI.swift (100%) rename Hyangyu/Hyangyu/Sources/APIServices/{ => AuthAPI}/SignUpService.swift (100%) diff --git a/Hyangyu/Hyangyu/Sources/APIServices/LoginAPI.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/LoginAPI.swift similarity index 100% rename from Hyangyu/Hyangyu/Sources/APIServices/LoginAPI.swift rename to Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/LoginAPI.swift diff --git a/Hyangyu/Hyangyu/Sources/APIServices/LoginService.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/LoginService.swift similarity index 100% rename from Hyangyu/Hyangyu/Sources/APIServices/LoginService.swift rename to Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/LoginService.swift diff --git a/Hyangyu/Hyangyu/Sources/APIServices/PasswordAPI.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift similarity index 100% rename from Hyangyu/Hyangyu/Sources/APIServices/PasswordAPI.swift rename to Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift diff --git a/Hyangyu/Hyangyu/Sources/APIServices/PasswordService.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift similarity index 100% rename from Hyangyu/Hyangyu/Sources/APIServices/PasswordService.swift rename to Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift diff --git a/Hyangyu/Hyangyu/Sources/APIServices/SignUpAPI.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/SignUpAPI.swift similarity index 100% rename from Hyangyu/Hyangyu/Sources/APIServices/SignUpAPI.swift rename to Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/SignUpAPI.swift diff --git a/Hyangyu/Hyangyu/Sources/APIServices/SignUpService.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/SignUpService.swift similarity index 100% rename from Hyangyu/Hyangyu/Sources/APIServices/SignUpService.swift rename to Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/SignUpService.swift From 5adbfbd746707fb64dbf08d811a8a9925fa6f0b7 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Mon, 7 Feb 2022 03:00:20 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[Feat]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20API=20=EC=84=9C=EB=B9=84=EC=8A=A4=EC=99=80?= =?UTF-8?q?=20URL=20=EC=B6=94=EA=B0=80=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 닉네임 변경 URL 추가 - 닉네임 변경 API 와 서비스 추가 --- Hyangyu/Hyangyu/Resources/Constants/URL.swift | 5 ++ .../APIServices/MyPageAPI/MyPageAPI.swift | 53 +++++++++++++++ .../APIServices/MyPageAPI/MyPageService.swift | 64 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift create mode 100644 Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift diff --git a/Hyangyu/Hyangyu/Resources/Constants/URL.swift b/Hyangyu/Hyangyu/Resources/Constants/URL.swift index 3bc3049..8cb666b 100644 --- a/Hyangyu/Hyangyu/Resources/Constants/URL.swift +++ b/Hyangyu/Hyangyu/Resources/Constants/URL.swift @@ -28,6 +28,11 @@ extension Const { // 회원 탈퇴 (DELETE) static let deleteUser = "/UserApi/user/deleteMyUser" + // MARK: - My Page - User Service + + // 닉네임 변경 (POST) + static let modifyUserName = "/UserApi/modifyUsername" + } } diff --git a/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift new file mode 100644 index 0000000..52e7329 --- /dev/null +++ b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift @@ -0,0 +1,53 @@ +// +// MyPageAPI.swift +// Hyangyu +// +// Created by 배소린 on 2022/02/07. +// + +import Foundation +import Moya + +public class MyPageAPI { + + static let shared = MyPageAPI() + var myPageProvider = MoyaProvider() + + public init() { } + + func modifyUserName(completion: @escaping (NetworkResult) -> Void, email: String, password: String, nickname: String) { + myPageProvider.request(.modifyUserName(email: email, password: password, nickname: nickname)) { + (result) in + + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + + case .failure(let err): + print(err) + } + } + } + + private func judgeStatus(by statusCode: Int, _ data: Data, _ object: T.Type) -> NetworkResult { + let decoder = JSONDecoder() + let welcome = try? decoder.decode(SignIn.self, from: data) + guard let decodedData = try? decoder.decode(GenericResponse.self, from: data as Data) + + else { + return .pathErr + } + + switch statusCode { + case 200: + return .success(welcome) + case 400..<500: + return .requestErr(decodedData.message) + case 500: + return .serverErr + default: + return .networkFail + } + } +} diff --git a/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift new file mode 100644 index 0000000..c662b33 --- /dev/null +++ b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift @@ -0,0 +1,64 @@ +// +// MyPageService.swift +// Hyangyu +// +// Created by 배소린 on 2022/02/07. +// + +import Foundation +import Moya + +enum MyPageService { + + case modifyUserName(email:String, password:String, nickname: String) + +} + +extension MyPageService: TargetType { + var baseURL: URL { + return URL(string: Const.URL.baseURL)! + } + var path: String { + switch self { + case .modifyUserName(_, _, _): + return Const.URL.modifyUserName + + + } + } + + var method: Moya.Method { + switch self { + case .modifyUserName(_, _, _): + return .post + + } + } + + var sampleData: Data { + return Data() + } + + var task: Task { + switch self { + case .modifyUserName(let email, let password, let nickname): + return .requestParameters(parameters: [ + "email": nil, + "password": nil, + "username": nickname, + ], encoding: JSONEncoding.default) + + } + } + + var headers: [String: String]? { + + switch self { + case .modifyUserName(_, _, _): + return [ + "Content-Type": "application/json", + "Bearer": UserDefaults.standard.string(forKey: "jwtToken") ?? "" + ] + } + } +} From 83387631cb53c7fa39bd3c7b767402a416cdeb85 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Mon, 7 Feb 2022 03:01:03 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[Feat]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20=ED=99=9C=EC=84=B1=ED=99=94=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 시작화면을 로그인 화면으로 활성화 --- Hyangyu/Hyangyu.xcodeproj/project.pbxproj | 36 +++++++++++++++++---- Hyangyu/Hyangyu/Sources/SceneDelegate.swift | 12 +++---- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Hyangyu/Hyangyu.xcodeproj/project.pbxproj b/Hyangyu/Hyangyu.xcodeproj/project.pbxproj index 540e577..9f15df6 100644 --- a/Hyangyu/Hyangyu.xcodeproj/project.pbxproj +++ b/Hyangyu/Hyangyu.xcodeproj/project.pbxproj @@ -69,6 +69,8 @@ 836086F827A6A59B00E9B9F5 /* Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 836086F727A6A59B00E9B9F5 /* Search.swift */; }; 8375EADB27B00D4E007D5EFA /* ServiceDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8375EADA27B00D4E007D5EFA /* ServiceDataModel.swift */; }; 8375EADD27B00F04007D5EFA /* CategoryTab.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 00D0CCB5278BC3DC0087EF87 /* CategoryTab.storyboard */; }; + 8375EAE527B02D88007D5EFA /* MyPageAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8375EAE427B02D88007D5EFA /* MyPageAPI.swift */; }; + 8375EAE827B02D9B007D5EFA /* MyPageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8375EAE727B02D9B007D5EFA /* MyPageService.swift */; }; 837763BC27A067E600248B6F /* SignUpUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 837763BB27A067E600248B6F /* SignUpUser.swift */; }; 837763C127A0892400248B6F /* MoyaLoggingPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 837763C027A0892400248B6F /* MoyaLoggingPlugin.swift */; }; 837763C427A0894B00248B6F /* SignUpService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 837763C327A0894B00248B6F /* SignUpService.swift */; }; @@ -194,6 +196,8 @@ 836086F427A6A58100E9B9F5 /* SearchTableViewHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchTableViewHeaderView.swift; sourceTree = ""; }; 836086F727A6A59B00E9B9F5 /* Search.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Search.swift; sourceTree = ""; }; 8375EADA27B00D4E007D5EFA /* ServiceDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceDataModel.swift; sourceTree = ""; }; + 8375EAE427B02D88007D5EFA /* MyPageAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageAPI.swift; sourceTree = ""; }; + 8375EAE727B02D9B007D5EFA /* MyPageService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageService.swift; sourceTree = ""; }; 837763BB27A067E600248B6F /* SignUpUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpUser.swift; sourceTree = ""; }; 837763C027A0892400248B6F /* MoyaLoggingPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoyaLoggingPlugin.swift; sourceTree = ""; }; 837763C327A0894B00248B6F /* SignUpService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpService.swift; sourceTree = ""; }; @@ -405,6 +409,28 @@ path = Views; sourceTree = ""; }; + 8375EAE227B02CA9007D5EFA /* AuthAPI */ = { + isa = PBXGroup; + children = ( + 837763C327A0894B00248B6F /* SignUpService.swift */, + 83B8A66227A1042B00C22495 /* SignUpAPI.swift */, + 83B8A66F27A10ECC00C22495 /* LoginAPI.swift */, + 83B8A67227A10EEA00C22495 /* LoginService.swift */, + 8307901927AB184500E0F7D4 /* PasswordAPI.swift */, + 8307901C27AB185F00E0F7D4 /* PasswordService.swift */, + ); + path = AuthAPI; + sourceTree = ""; + }; + 8375EAE327B02D76007D5EFA /* MyPageAPI */ = { + isa = PBXGroup; + children = ( + 8375EAE427B02D88007D5EFA /* MyPageAPI.swift */, + 8375EAE727B02D9B007D5EFA /* MyPageService.swift */, + ); + path = MyPageAPI; + sourceTree = ""; + }; 837763BA27A067D400248B6F /* AppModels */ = { isa = PBXGroup; children = ( @@ -419,15 +445,11 @@ 837763BF27A088A400248B6F /* APIServices */ = { isa = PBXGroup; children = ( + 8375EAE327B02D76007D5EFA /* MyPageAPI */, + 8375EAE227B02CA9007D5EFA /* AuthAPI */, 837763C027A0892400248B6F /* MoyaLoggingPlugin.swift */, - 837763C327A0894B00248B6F /* SignUpService.swift */, - 83B8A66227A1042B00C22495 /* SignUpAPI.swift */, 83B8A66527A1048C00C22495 /* NetworkResult.swift */, 83B8A66827A104C800C22495 /* GenericResponse.swift */, - 83B8A66F27A10ECC00C22495 /* LoginAPI.swift */, - 83B8A67227A10EEA00C22495 /* LoginService.swift */, - 8307901927AB184500E0F7D4 /* PasswordAPI.swift */, - 8307901C27AB185F00E0F7D4 /* PasswordService.swift */, ); path = APIServices; sourceTree = ""; @@ -812,6 +834,7 @@ 0079288D2797E44C006B8EDE /* CategoryCollectionViewCell.swift in Sources */, 23842AA4279EBCF800621427 /* HomeHashtagDataModel.swift in Sources */, 83B34E01278735FF009A8009 /* AppDelegate.swift in Sources */, + 8375EAE527B02D88007D5EFA /* MyPageAPI.swift in Sources */, 23842A95279EBCD600621427 /* ReviewViewController.swift in Sources */, 23842AA6279EBCF800621427 /* HashtagDetailDataModel.swift in Sources */, 23842A94279EBCD600621427 /* ReviewEditViewController.swift in Sources */, @@ -852,6 +875,7 @@ 836086F227A6A55600E9B9F5 /* SearchResultCell.swift in Sources */, 837763C127A0892400248B6F /* MoyaLoggingPlugin.swift in Sources */, 8399CF8E27994DB9002E5287 /* UIFont.swift in Sources */, + 8375EAE827B02D9B007D5EFA /* MyPageService.swift in Sources */, 83E42363279ACB850094DC2E /* UIImage+Extensions.swift in Sources */, 837763C427A0894B00248B6F /* SignUpService.swift in Sources */, 8399CF6F27994775002E5287 /* UIScrollView+Extensions.swift in Sources */, diff --git a/Hyangyu/Hyangyu/Sources/SceneDelegate.swift b/Hyangyu/Hyangyu/Sources/SceneDelegate.swift index 792c3ce..a3ffba4 100644 --- a/Hyangyu/Hyangyu/Sources/SceneDelegate.swift +++ b/Hyangyu/Hyangyu/Sources/SceneDelegate.swift @@ -19,12 +19,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). -// if !hasJwtToken() { -// setRootViewControllerToLogin() -// } else { -// print(UserDefaults.standard.string(forKey: "jwtToken")) -// setRootViewControllerToTabbar() -// } + if !hasJwtToken() { + setRootViewControllerToLogin() + } else { + print(UserDefaults.standard.string(forKey: "jwtToken")) + setRootViewControllerToTabbar() + } self.window?.backgroundColor = .white guard let _ = (scene as? UIWindowScene) else { return } From 24c09f1677720f4d13050486dc38ad51e035ece7 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Mon, 7 Feb 2022 20:20:47 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[Feat]=20=EC=84=9C=EB=B2=84=20URL=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 서버 URL 수정 - 닉네임 변경, 유저 조회 URL 추가 --- Hyangyu/Hyangyu/Resources/Constants/URL.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Hyangyu/Hyangyu/Resources/Constants/URL.swift b/Hyangyu/Hyangyu/Resources/Constants/URL.swift index 8cb666b..ef7a27b 100644 --- a/Hyangyu/Hyangyu/Resources/Constants/URL.swift +++ b/Hyangyu/Hyangyu/Resources/Constants/URL.swift @@ -11,14 +11,14 @@ extension Const { struct URL { // base url - static let baseURL = "http://13.209.87.36:8080/api" + static let baseURL = "http://52.79.236.231:8080/api" // MARK: - Auth - Auth Service // 회원가입 (POST) static let signUpURL = "/UserApi/signup" - // 로그인 (GET) + // 로그인 (POST) static let signInURL = "/AuthController/authenticate" @@ -31,7 +31,11 @@ extension Const { // MARK: - My Page - User Service // 닉네임 변경 (POST) - static let modifyUserName = "/UserApi/modifyUsername" + static let modifyUserName = "/UserApi/user/modifyUsername" + + // 유저 조회 (GET) + static let userView = "/api/UserApi/user" + } } From 0b361a94067eb1425905de71712f7c9205022150 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Mon, 7 Feb 2022 20:22:54 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[Feat]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B7=B0=20=ED=86=B5=EC=8B=A0=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 닉네임 변경 뷰 통신 연결 --- .../Hyangyu/Sources/APIModels/MyPage.swift | 13 +++ .../APIServices/MyPageAPI/MyPageAPI.swift | 26 ++++-- .../APIServices/MyPageAPI/MyPageService.swift | 34 ++++++-- Hyangyu/Hyangyu/Sources/AppModels/User.swift | 16 ++++ .../MyPage/ProfileEditViewController.swift | 80 ++++++++++++++++++- 5 files changed, 154 insertions(+), 15 deletions(-) create mode 100644 Hyangyu/Hyangyu/Sources/APIModels/MyPage.swift create mode 100644 Hyangyu/Hyangyu/Sources/AppModels/User.swift diff --git a/Hyangyu/Hyangyu/Sources/APIModels/MyPage.swift b/Hyangyu/Hyangyu/Sources/APIModels/MyPage.swift new file mode 100644 index 0000000..7997be5 --- /dev/null +++ b/Hyangyu/Hyangyu/Sources/APIModels/MyPage.swift @@ -0,0 +1,13 @@ +// +// MyPage.swift +// Hyangyu +// +// Created by 배소린 on 2022/02/07. +// + +import Foundation + +// MARK: - message +struct ModifyCheckData: Codable { + let message: String +} diff --git a/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift index 52e7329..e7c862e 100644 --- a/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift +++ b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift @@ -18,11 +18,12 @@ public class MyPageAPI { func modifyUserName(completion: @escaping (NetworkResult) -> Void, email: String, password: String, nickname: String) { myPageProvider.request(.modifyUserName(email: email, password: password, nickname: nickname)) { (result) in - switch result { case .success(let response): let statusCode = response.statusCode let data = response.data + let networkResult = self.judgeStatus(by: statusCode, data) + completion(networkResult) case .failure(let err): print(err) @@ -30,18 +31,31 @@ public class MyPageAPI { } } - private func judgeStatus(by statusCode: Int, _ data: Data, _ object: T.Type) -> NetworkResult { + func getUserInfo(completion: @escaping (NetworkResult) -> Void) { + myPageProvider.request(.getUserInfo) { (result) in + print(result) + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + let networkResult = self.judgeStatus(by: statusCode, data) + completion(networkResult) + case .failure(let err): + print(err) + } + } + } + + private func judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult { let decoder = JSONDecoder() - let welcome = try? decoder.decode(SignIn.self, from: data) - guard let decodedData = try? decoder.decode(GenericResponse.self, from: data as Data) - + guard let decodedData = try? decoder.decode(GenericResponse.self, from: data as Data) else { return .pathErr } switch statusCode { case 200: - return .success(welcome) + return .success(decodedData.data) case 400..<500: return .requestErr(decodedData.message) case 500: diff --git a/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift index c662b33..5f752b3 100644 --- a/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift +++ b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift @@ -11,10 +11,16 @@ import Moya enum MyPageService { case modifyUserName(email:String, password:String, nickname: String) - + + case getUserInfo + } -extension MyPageService: TargetType { +extension MyPageService: TargetType, AccessTokenAuthorizable { + var authorizationType: AuthorizationType? { + return .bearer + } + var baseURL: URL { return URL(string: Const.URL.baseURL)! } @@ -22,8 +28,10 @@ extension MyPageService: TargetType { switch self { case .modifyUserName(_, _, _): return Const.URL.modifyUserName - - + case .getUserInfo: + return Const.URL.userView + + } } @@ -31,7 +39,9 @@ extension MyPageService: TargetType { switch self { case .modifyUserName(_, _, _): return .post - + case .getUserInfo: + return .get + } } @@ -39,6 +49,7 @@ extension MyPageService: TargetType { return Data() } + var task: Task { switch self { case .modifyUserName(let email, let password, let nickname): @@ -47,17 +58,24 @@ extension MyPageService: TargetType { "password": nil, "username": nickname, ], encoding: JSONEncoding.default) - + case .getUserInfo: + return .requestPlain + } } var headers: [String: String]? { - + switch self { case .modifyUserName(_, _, _): return [ "Content-Type": "application/json", - "Bearer": UserDefaults.standard.string(forKey: "jwtToken") ?? "" + "Authorization": "Bearer \(UserDefaults.standard.string(forKey: "jwtToken") ?? "")" + ] + case .getUserInfo: + return [ + "Authorization": "Bearer \(UserDefaults.standard.string(forKey: "jwtToken") ?? "")", + "Content-Type": "application/json", ] } } diff --git a/Hyangyu/Hyangyu/Sources/AppModels/User.swift b/Hyangyu/Hyangyu/Sources/AppModels/User.swift new file mode 100644 index 0000000..4adff85 --- /dev/null +++ b/Hyangyu/Hyangyu/Sources/AppModels/User.swift @@ -0,0 +1,16 @@ +// +// User.swift +// Hyangyu +// +// Created by 배소린 on 2022/02/07. +// + +import Foundation +import UIKit + +class User { + static let shared = User() + + var username: String? + var profileImage: UIImage? +} diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift index 0c78197..aecf2e9 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift @@ -20,10 +20,15 @@ struct ProfileEditViewControllerViewModel { final class ProfileEditViewController: UIViewController { // MARK: - Properties + private var user = User.shared + var userName: String = "" var userProfileImage: UIImage = UIImage() + private var nameCount: Int = 0 private var isAbleToSubmit: Bool = true + private var isKeyboardOn: Bool = false + private var keyboardHeight: CGFloat = 0 private var maxLength = 10 // MARK: - @IBOutlet @@ -75,7 +80,9 @@ final class ProfileEditViewController: UIViewController { @IBAction func didTapConfirm(_ sender: Any) { delegate?.setUpdate(profileImage: userProfileImageView?.image, userName: userNameTextField?.text) - dismiss(animated: true, completion: nil) + user.username = userNameTextField.text ?? "" + user.profileImage = userProfileImageView.image ?? nil + modifyUserName() } @@ -93,6 +100,8 @@ final class ProfileEditViewController: UIViewController { private func setUserNameTextField() { userNameTextField.addTarget(self, action: #selector(self.checkTextField), for: .editingChanged) + NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) } @objc func checkTextField () { @@ -116,6 +125,18 @@ final class ProfileEditViewController: UIViewController { } } + // 키보드 Notification + @objc private func keyboardWillShow(_ notification: Notification) { + if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { + keyboardHeight = keyboardFrame.cgRectValue.height + } + isKeyboardOn = true + } + @objc private func keyboardWillHide(_ notification: Notification) { + keyboardHeight = 0 + isKeyboardOn = false + } + private func setWithNoneText() { userNameTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) countingLabel.isHidden = true @@ -147,6 +168,39 @@ final class ProfileEditViewController: UIViewController { actionSheetAlert() } + // 토스트 메세지 + private func showToast(message: String) { + let isKeyboardOn: Bool = self.isKeyboardOn + let keyboardHeight: CGFloat = self.keyboardHeight + var toastLabel = UILabel() + // 토스트 위치 + if isKeyboardOn { + toastLabel = UILabel(frame: CGRect(x: 30, + y: self.view.frame.size.height - keyboardHeight - 59, + width: self.view.frame.size.width - 60, + height: 40)) + } else { + toastLabel = UILabel(frame: CGRect(x: 30, + y: self.view.frame.size.height - 95, + width: self.view.frame.size.width - 60, + height: 40)) + } + // 토스트 색 + toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6) + toastLabel.textColor = UIColor.white + // 토스트 값 + toastLabel.text = message + // 토스트 모양 + toastLabel.textAlignment = .center + toastLabel.layer.cornerRadius = 12 + toastLabel.clipsToBounds = true + // 토스트 애니메이션 + self.view.addSubview(toastLabel) + UIView.animate(withDuration: 1.0, delay: 0.1, + options: .curveEaseIn, animations: { toastLabel.alpha = 0.0 }, + completion: {_ in toastLabel.removeFromSuperview() }) + } + @@ -236,3 +290,27 @@ extension ProfileEditViewController: UITextFieldDelegate { } } + +extension ProfileEditViewController { + func modifyUserName() { + guard let userName = User.shared.username else { return } + + MyPageAPI.shared.modifyUserName(completion: { (response) in + switch response { + case .success: + self.showToast(message: "닉네임 변경에 성공하였습니다") + DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { + self.dismiss(animated: true) + } + case .requestErr(let message): + print("requestErr", message) + case .pathErr: + print(".pathErr") + case .serverErr: + print("serverErr") + case .networkFail: + print("networkFail") + } + }, email: "", password: "", nickname: userName) + } +} From 3facad1f8a62aca2d4527736bfd3a0696e40c7b4 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Mon, 7 Feb 2022 20:23:49 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[Feat]=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EB=B7=B0=20=ED=86=A0=EC=8A=A4=ED=8A=B8=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EC=88=98=EC=A0=95=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 회원가입 뷰 토스트메세지 수정 --- .../Sources/ViewControllers/SignIn/SignInViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/SignIn/SignInViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/SignIn/SignInViewController.swift index 909a2bc..f096c70 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/SignIn/SignInViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/SignIn/SignInViewController.swift @@ -92,7 +92,7 @@ class SignInViewController: UIViewController { y: self.view.frame.size.height/2, width: self.view.frame.size.width - 40, height: 47)) - toastLabel.backgroundColor = .black + toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6) toastLabel.textColor = .white toastLabel.text = message toastLabel.textAlignment = .center From 688a59598a19ba7a581495ec0cbfea43e52b2e6f Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Mon, 7 Feb 2022 20:26:23 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[Chore]=20=EC=84=9C=EC=B9=98=20VC=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=EC=97=86=EB=8A=94=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 서치 VC 필요없는 코드 삭제 --- Hyangyu/Hyangyu.xcodeproj/project.pbxproj | 8 ++++ .../Search/SearchResultsViewController.swift | 43 ++++++++----------- .../Search/SearchViewController.swift | 2 + 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Hyangyu/Hyangyu.xcodeproj/project.pbxproj b/Hyangyu/Hyangyu.xcodeproj/project.pbxproj index 9f15df6..734926c 100644 --- a/Hyangyu/Hyangyu.xcodeproj/project.pbxproj +++ b/Hyangyu/Hyangyu.xcodeproj/project.pbxproj @@ -121,6 +121,8 @@ 83C167CD279DF4DE00A4F289 /* SearchResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C167CC279DF4DE00A4F289 /* SearchResult.swift */; }; 83CA48CF27AF187E00F38EC6 /* SearchHeaderCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83CA48CE27AF187E00F38EC6 /* SearchHeaderCollectionReusableView.swift */; }; 83CA48D227AF1DD500F38EC6 /* SearchResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83CA48D127AF1DD500F38EC6 /* SearchResultView.swift */; }; + 83DADD6027B12B51001DCE44 /* MyPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DADD5F27B12B51001DCE44 /* MyPage.swift */; }; + 83DADD6327B13255001DCE44 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DADD6227B13255001DCE44 /* User.swift */; }; 83E2A0E927AC1E2900EB0A55 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E2A0E827AC1E2900EB0A55 /* SearchView.swift */; }; 83E42363279ACB850094DC2E /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E42362279ACB850094DC2E /* UIImage+Extensions.swift */; }; 83E42366279ACD890094DC2E /* UITextField+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E42365279ACD890094DC2E /* UITextField+Extensions.swift */; }; @@ -249,6 +251,8 @@ 83C167CC279DF4DE00A4F289 /* SearchResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResult.swift; sourceTree = ""; }; 83CA48CE27AF187E00F38EC6 /* SearchHeaderCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHeaderCollectionReusableView.swift; sourceTree = ""; }; 83CA48D127AF1DD500F38EC6 /* SearchResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultView.swift; sourceTree = ""; }; + 83DADD5F27B12B51001DCE44 /* MyPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPage.swift; sourceTree = ""; }; + 83DADD6227B13255001DCE44 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; 83E2A0E827AC1E2900EB0A55 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = ""; }; 83E42362279ACB850094DC2E /* UIImage+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Extensions.swift"; sourceTree = ""; }; 83E42365279ACD890094DC2E /* UITextField+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField+Extensions.swift"; sourceTree = ""; }; @@ -438,6 +442,7 @@ 83177BD527AD6F4A00032BF3 /* Product.swift */, 836086F727A6A59B00E9B9F5 /* Search.swift */, 8375EADA27B00D4E007D5EFA /* ServiceDataModel.swift */, + 83DADD6227B13255001DCE44 /* User.swift */, ); path = AppModels; sourceTree = ""; @@ -605,6 +610,7 @@ isa = PBXGroup; children = ( 83B8A65F27A103C100C22495 /* Auth.swift */, + 83DADD5F27B12B51001DCE44 /* MyPage.swift */, ); path = APIModels; sourceTree = ""; @@ -825,6 +831,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 83DADD6027B12B51001DCE44 /* MyPage.swift in Sources */, 0093448627AFAEB000490D57 /* WriteReviewViewController.swift in Sources */, 0093448427AFAE7F00490D57 /* MoreReviewViewController.swift in Sources */, 0099690327A16FFC00D7CDA2 /* DetailPageViewController.swift in Sources */, @@ -916,6 +923,7 @@ 8399CF8B27994DA0002E5287 /* UIColor+RGB.swift in Sources */, 83B8A66627A1048C00C22495 /* NetworkResult.swift in Sources */, 832DFDB32795744500CBFC13 /* MyPageViewController.swift in Sources */, + 83DADD6327B13255001DCE44 /* User.swift in Sources */, 8349587527987AB60045B419 /* TabBarViewController.swift in Sources */, 83B8A67027A10ECC00C22495 /* LoginAPI.swift in Sources */, 8399CF7A27994B2C002E5287 /* CustomChildViewController.swift in Sources */, diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/Search/SearchResultsViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/Search/SearchResultsViewController.swift index 9ecb548..ce56635 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/Search/SearchResultsViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/Search/SearchResultsViewController.swift @@ -12,13 +12,13 @@ struct SearchSection { let results: [SearchResult] } -//protocol SearchResultsViewControllerDelegate: AnyObject { -// func didTapResult(_ result: SearchResult) -//} +protocol SearchResultsViewConrollerDelegate: AnyObject { + func didTapResult(_ result: SearchResult) +} class SearchResultsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { -// weak var delegate : SearchResultsViewContollerDelegate? + weak var delegate : SearchResultsViewConrollerDelegate? private var sections: [SearchSection] = [] @@ -80,8 +80,6 @@ class SearchResultsViewController: UIViewController, UITableViewDelegate, UITabl tableView.isHidden = results.isEmpty } - func search(term: String) { - } func numberOfSections(in tableView: UITableView) -> Int { return sections.count @@ -96,8 +94,8 @@ class SearchResultsViewController: UIViewController, UITableViewDelegate, UITabl switch result { case .exhibition(let exhibition): guard let cell = tableView.dequeueReusableCell( - withIdentifier: SearchResultsTableViewCell.identifier, - for: indexPath + withIdentifier: SearchResultsTableViewCell.identifier, + for: indexPath ) as? SearchResultsTableViewCell else { return UITableViewCell() } @@ -112,8 +110,8 @@ class SearchResultsViewController: UIViewController, UITableViewDelegate, UITabl return cell case .expo(let expo): guard let cell = tableView.dequeueReusableCell( - withIdentifier: SearchResultsTableViewCell.identifier, - for: indexPath + withIdentifier: SearchResultsTableViewCell.identifier, + for: indexPath ) as? SearchResultsTableViewCell else { return UITableViewCell() } @@ -128,8 +126,8 @@ class SearchResultsViewController: UIViewController, UITableViewDelegate, UITabl return cell case .festival(let festival): guard let cell = tableView.dequeueReusableCell( - withIdentifier: SearchResultsTableViewCell.identifier, - for: indexPath + withIdentifier: SearchResultsTableViewCell.identifier, + for: indexPath ) as? SearchResultsTableViewCell else { return UITableViewCell() } @@ -145,12 +143,6 @@ class SearchResultsViewController: UIViewController, UITableViewDelegate, UITabl } } -// func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { -// tableView.deselectRow(at: indexPath, animated: true) -// let result = sections[indexPath.section].results[indexPath.row] -// delegate?.didTapResult(result) -// -// } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let headerView = UIView() @@ -165,17 +157,20 @@ class SearchResultsViewController: UIViewController, UITableViewDelegate, UITabl $0.font = UIFont(name: FontType.appleSDGothicNeoSemiBold.rawValue, size: 15) $0.text = "(\(sections[section].results.count))" } + let moreButton = UIButton().then { + $0.setImage(UIImage(systemName: "chevron.right"), for: .normal) + $0.tintColor = .black + } titleLabel.frame = CGRect(x: 20, y: 0, width: headerView.frame.width, height: headerView.frame.height) - countLabel.frame = CGRect(x: headerView.frame.width - 50, y: 0, width: 50, height: 50) - headerView.addSubview(titleLabel) + countLabel.frame = CGRect(x: headerView.frame.width - 60, y: 0, width: 50, height: 50) + moreButton.frame = CGRect(x: headerView.frame.width - 30, y: 0, width: 10, height: 50) + headerView.addSubview(titleLabel) headerView.addSubview(countLabel) - - return headerView - - + return headerView } + func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sections[section].title } diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/Search/SearchViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/Search/SearchViewController.swift index 997e316..d122440 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/Search/SearchViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/Search/SearchViewController.swift @@ -208,3 +208,5 @@ extension SearchViewController: UICollectionViewDelegateFlowLayout { return CGSize(width: collectionView.frame.width, height: 40) } } + +