diff --git a/Hyangyu/Hyangyu.xcodeproj/project.pbxproj b/Hyangyu/Hyangyu.xcodeproj/project.pbxproj index e539e6c..951975b 100644 --- a/Hyangyu/Hyangyu.xcodeproj/project.pbxproj +++ b/Hyangyu/Hyangyu.xcodeproj/project.pbxproj @@ -81,6 +81,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 */; }; @@ -131,6 +133,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 */; }; @@ -212,6 +216,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 = ""; }; @@ -263,6 +269,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 = ""; }; @@ -435,6 +443,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 = ( @@ -443,6 +473,7 @@ 836086F727A6A59B00E9B9F5 /* Search.swift */, 8375EADA27B00D4E007D5EFA /* ServiceDataModel.swift */, 0003779927B0F6E200724152 /* ReviewModel.swift */, + 83DADD6227B13255001DCE44 /* User.swift */, ); path = AppModels; sourceTree = ""; @@ -450,15 +481,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 = ""; @@ -613,6 +640,7 @@ isa = PBXGroup; children = ( 83B8A65F27A103C100C22495 /* Auth.swift */, + 83DADD5F27B12B51001DCE44 /* MyPage.swift */, ); path = APIModels; sourceTree = ""; @@ -840,6 +868,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 83DADD6027B12B51001DCE44 /* MyPage.swift in Sources */, 0093448627AFAEB000490D57 /* WriteReviewViewController.swift in Sources */, 0003779A27B0F6E200724152 /* ReviewModel.swift in Sources */, 0093448427AFAE7F00490D57 /* MoreReviewViewController.swift in Sources */, @@ -851,6 +880,7 @@ 0003779727B0F05800724152 /* ReviewCollectionViewCell.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 */, @@ -892,6 +922,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 */, @@ -936,6 +967,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/Resources/Constants/URL.swift b/Hyangyu/Hyangyu/Resources/Constants/URL.swift index 3bc3049..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" @@ -28,6 +28,15 @@ extension Const { // 회원 탈퇴 (DELETE) static let deleteUser = "/UserApi/user/deleteMyUser" + // MARK: - My Page - User Service + + // 닉네임 변경 (POST) + static let modifyUserName = "/UserApi/user/modifyUsername" + + // 유저 조회 (GET) + static let userView = "/api/UserApi/user" + + } } 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/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 diff --git a/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift new file mode 100644 index 0000000..e7c862e --- /dev/null +++ b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.swift @@ -0,0 +1,67 @@ +// +// 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 + let networkResult = self.judgeStatus(by: statusCode, data) + completion(networkResult) + + case .failure(let err): + print(err) + } + } + } + + 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() + guard let decodedData = try? decoder.decode(GenericResponse.self, from: data as Data) + else { + return .pathErr + } + + switch statusCode { + case 200: + return .success(decodedData.data) + case 400..<500: + return .requestErr(decodedData.message) + case 500: + return .serverErr + default: + return .networkFail + } + } +} diff --git a/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift new file mode 100644 index 0000000..5f752b3 --- /dev/null +++ b/Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.swift @@ -0,0 +1,82 @@ +// +// MyPageService.swift +// Hyangyu +// +// Created by 배소린 on 2022/02/07. +// + +import Foundation +import Moya + +enum MyPageService { + + case modifyUserName(email:String, password:String, nickname: String) + + case getUserInfo + +} + +extension MyPageService: TargetType, AccessTokenAuthorizable { + var authorizationType: AuthorizationType? { + return .bearer + } + + var baseURL: URL { + return URL(string: Const.URL.baseURL)! + } + var path: String { + switch self { + case .modifyUserName(_, _, _): + return Const.URL.modifyUserName + case .getUserInfo: + return Const.URL.userView + + + } + } + + var method: Moya.Method { + switch self { + case .modifyUserName(_, _, _): + return .post + case .getUserInfo: + return .get + + } + } + + 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) + case .getUserInfo: + return .requestPlain + + } + } + + var headers: [String: String]? { + + switch self { + case .modifyUserName(_, _, _): + return [ + "Content-Type": "application/json", + "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/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 } 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) + } +} 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) } } + + 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