From f645a00ef700011f9a201d317d413e1e80e72497 Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:26:32 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Feat]=20#65=20-=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20API=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS.xcodeproj/project.pbxproj | 8 +++ .../Network/Dto/MyPageDto/MyPageDto.swift | 24 ++++++++ .../Router/MyPageRouter/MyPageRouter.swift | 52 ++++++++++++++++ .../Presentation/MyPage/VC/MyPageVC.swift | 61 +++++++++++++++++-- .../Presentation/Splash/VC/SplashVC.swift | 1 - 5 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift create mode 100644 Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index c3e29e6c..b097f3ba 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -19,6 +19,8 @@ A3BC2F3F2964706100198261 /* UploadedCourseInfoCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F3E2964706100198261 /* UploadedCourseInfoCVC.swift */; }; A3BC2F4129667A0D00198261 /* NicknameEditorVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F4029667A0D00198261 /* NicknameEditorVC.swift */; }; A3BC2F432966A93100198261 /* CourseDetailVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F422966A93100198261 /* CourseDetailVC.swift */; }; + A3F67AE2296D33AC001598A2 /* MyPageDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE1296D33AC001598A2 /* MyPageDto.swift */; }; + A3F67AE4296D33E0001598A2 /* MyPageRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */; }; CE0C23742966D62A00B45063 /* PagedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0C23732966D62A00B45063 /* PagedView.swift */; }; CE0C23772966D64D00B45063 /* PageCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0C23762966D64D00B45063 /* PageCVC.swift */; }; CE0C23792966D6AF00B45063 /* ViewPager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0C23782966D6AF00B45063 /* ViewPager.swift */; }; @@ -143,6 +145,8 @@ A3BC2F3E2964706100198261 /* UploadedCourseInfoCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadedCourseInfoCVC.swift; sourceTree = ""; }; A3BC2F4029667A0D00198261 /* NicknameEditorVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameEditorVC.swift; sourceTree = ""; }; A3BC2F422966A93100198261 /* CourseDetailVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailVC.swift; sourceTree = ""; }; + A3F67AE1296D33AC001598A2 /* MyPageDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageDto.swift; sourceTree = ""; }; + A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageRouter.swift; sourceTree = ""; }; CE0C23732966D62A00B45063 /* PagedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagedView.swift; sourceTree = ""; }; CE0C23762966D64D00B45063 /* PageCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageCVC.swift; sourceTree = ""; }; CE0C23782966D6AF00B45063 /* ViewPager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPager.swift; sourceTree = ""; }; @@ -394,6 +398,7 @@ isa = PBXGroup; children = ( CE10063D29680C8100FD31FB /* .gitkeep */, + A3F67AE1296D33AC001598A2 /* MyPageDto.swift */, ); path = MyPageDto; sourceTree = ""; @@ -724,6 +729,7 @@ isa = PBXGroup; children = ( CE10064329680CB400FD31FB /* .gitkeep */, + A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */, ); path = MyPageRouter; sourceTree = ""; @@ -1282,7 +1288,9 @@ CE6B63D6296731F9003F900F /* ScrapCourseListView.swift in Sources */, DA20D841296696C300F1581F /* MapCollectionViewCell.swift in Sources */, CE6655F8295D90CF00C64E12 /* adjusted+.swift in Sources */, + A3F67AE4296D33E0001598A2 /* MyPageRouter.swift in Sources */, CE4545CB295D7AF4003201E1 /* SceneDelegate.swift in Sources */, + A3F67AE2296D33AC001598A2 /* MyPageDto.swift in Sources */, A3BC2F3F2964706100198261 /* UploadedCourseInfoCVC.swift in Sources */, CE6655FE295D912300C64E12 /* calculateTopInset.swift in Sources */, CEEC6B492961C5E200D00E1E /* SplashVC.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift new file mode 100644 index 00000000..1811ea9b --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift @@ -0,0 +1,24 @@ +// +// MyPageDto.swift +// Runnect-iOS +// +// Created by 몽이 누나 on 2023/01/10. +// + +import Foundation + +// MARK: - MyPageDto +struct MyPageDto: Codable { + let user: User +} + +// MARK: - User +struct User: Codable { + let machineID, nickname, latestStamp: String + let level, levelPercent: Int + + enum CodingKeys: String, CodingKey { + case machineID = "machineId" + case nickname, latestStamp, level, levelPercent + } +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift new file mode 100644 index 00000000..df667025 --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift @@ -0,0 +1,52 @@ +// +// MyPageRouter.swift +// Runnect-iOS +// +// Created by 몽이 누나 on 2023/01/10. +// + +import Foundation + +import Moya + +enum MyPageRouter { + case getMyPageInfo +} + +extension MyPageRouter: TargetType { + var baseURL: URL { + guard let url = URL(string: Config.baseURL) else { + fatalError("baseURL could not be configured") + } + + return url + } + + var path: String { + switch self { + case .getMyPageInfo: + return "/user" + } + } + + var method: Moya.Method { + switch self { + case .getMyPageInfo: + return .get + } + } + + var task: Moya.Task { + switch self { + case .getMyPageInfo: + return .requestPlain + } + } + + var headers: [String: String]? { + switch self { + case .getMyPageInfo: + return Config.headerWithDeviceId + } + } +} diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift index 57bf95cf..9384984c 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift @@ -6,11 +6,21 @@ // import UIKit + import SnapKit import Then +import Moya final class MyPageVC: UIViewController { + // MARK: - Properties + + private var myPageProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) + + private var myLevelPercent = Int() + // MARK: - UI Components private lazy var navibar = CustomNavigationBar(self, type: .title).setTitle("마이페이지") @@ -25,7 +35,6 @@ final class MyPageVC: UIViewController { } private let myProfileNameLabel = UILabel().then { - $0.text = "말랑콩떡" $0.textColor = .m1 $0.font = .h4 } @@ -50,9 +59,9 @@ final class MyPageVC: UIViewController { $0.font = .h5 } - private let myRunningProgressBar = UIProgressView(progressViewStyle: .bar).then { + private lazy var myRunningProgressBar = UIProgressView(progressViewStyle: .bar).then { $0.translatesAutoresizingMaskIntoConstraints = false - $0.setProgress(0.25, animated: false) + $0.setProgress(Float(self.myLevelPercent)/100, animated: false) $0.progressTintColor = .m1 $0.trackTintColor = .m3 $0.layer.cornerRadius = 6 @@ -61,8 +70,8 @@ final class MyPageVC: UIViewController { $0.subviews[1].clipsToBounds = true } - private let myRunnigProgressPercentLabel = UILabel().then { - let attributedString = NSMutableAttributedString(string: "25", attributes: [.font: UIFont.b5, .foregroundColor: UIColor.g1]) + private lazy var myRunnigProgressPercentLabel = UILabel().then { + let attributedString = NSMutableAttributedString(string: String(self.myLevelPercent), attributes: [.font: UIFont.b5, .foregroundColor: UIColor.g1]) attributedString.append(NSAttributedString(string: " /100", attributes: [.font: UIFont.b5, .foregroundColor: UIColor.g2])) $0.attributedText = attributedString } @@ -89,6 +98,7 @@ final class MyPageVC: UIViewController { setNavigationBar() setUI() setLayout() + getMyPageInfo() } } @@ -153,6 +163,11 @@ extension MyPageVC { nicknameEditorVC.modalPresentationStyle = .overFullScreen self.present(nicknameEditorVC, animated: false) } + + private func setData(model: MyPageDto) { + self.myProfileNameLabel.text = model.user.nickname + self.myLevelPercent = model.user.levelPercent + } } // MARK: - @objc Function @@ -304,3 +319,39 @@ extension MyPageVC { } } } + +// MARK: - Network + +extension MyPageVC { + func getMyPageInfo() { + LoadingIndicator.showLoading() + myPageProvider.request(.getMyPageInfo) { [weak self] response in + LoadingIndicator.hideLoading() + guard let self = self else { return } + switch response { + case .success(let result): + let status = result.statusCode + if 200..<300 ~= status { + do { + let responseDto = try result.map(BaseResponse.self) + if responseDto.status == 200 { + guard let data = responseDto.data else { return } + self.setData(model: data) + } else { + self.showToast(message: responseDto.message) + } + } catch { + print(error.localizedDescription) + } + } + if status >= 400 { + print("400 error") + self.showNetworkFailureToast() + } + case .failure(let error): + print(error.localizedDescription) + self.showNetworkFailureToast() + } + } + } +} diff --git a/Runnect-iOS/Runnect-iOS/Presentation/Splash/VC/SplashVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/Splash/VC/SplashVC.swift index 59385253..3230a3b1 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/Splash/VC/SplashVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/Splash/VC/SplashVC.swift @@ -41,7 +41,6 @@ extension SplashVC { private func checkDidSignIn() { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { let deviceId = KeychainManager.shared.getDeviceId() - if deviceId.isEmpty { let deviceIdStoreSuccess = KeychainManager.shared.storeDeviceId() guard deviceIdStoreSuccess else { return } From ecec92c0503148193d60c8b6a732db8187504533 Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Tue, 10 Jan 2023 22:52:37 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[Fix]=20#65=20-=20setData=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 서버통신 이후 UI에 받아 온 데이터 값이 반영될 수 있도록 수정 --- .../Presentation/MyPage/VC/MyPageVC.swift | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift index 9384984c..08f8ec13 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift @@ -18,9 +18,7 @@ final class MyPageVC: UIViewController { private var myPageProvider = MoyaProvider( plugins: [NetworkLoggerPlugin(verbose: true)] ) - - private var myLevelPercent = Int() - + // MARK: - UI Components private lazy var navibar = CustomNavigationBar(self, type: .title).setTitle("마이페이지") @@ -53,15 +51,11 @@ final class MyPageVC: UIViewController { $0.addGestureRecognizer(tap) } - private let myRunningLevelLavel = UILabel().then { - $0.text = "LV 3" - $0.textColor = .g1 - $0.font = .h5 - } + private let myRunningLevelLavel = UILabel() private lazy var myRunningProgressBar = UIProgressView(progressViewStyle: .bar).then { $0.translatesAutoresizingMaskIntoConstraints = false - $0.setProgress(Float(self.myLevelPercent)/100, animated: false) + $0.setProgress(0, animated: false) $0.progressTintColor = .m1 $0.trackTintColor = .m3 $0.layer.cornerRadius = 6 @@ -70,11 +64,7 @@ final class MyPageVC: UIViewController { $0.subviews[1].clipsToBounds = true } - private lazy var myRunnigProgressPercentLabel = UILabel().then { - let attributedString = NSMutableAttributedString(string: String(self.myLevelPercent), attributes: [.font: UIFont.b5, .foregroundColor: UIColor.g1]) - attributedString.append(NSAttributedString(string: " /100", attributes: [.font: UIFont.b5, .foregroundColor: UIColor.g2])) - $0.attributedText = attributedString - } + private let myRunnigProgressPercentLabel = UILabel() private lazy var goalRewardInfoView = makeInfoView(title: "목표 보상").then { let tap = UITapGestureRecognizer(target: self, action: #selector(self.touchUpGoalRewardInfoView)) @@ -166,8 +156,23 @@ extension MyPageVC { private func setData(model: MyPageDto) { self.myProfileNameLabel.text = model.user.nickname - self.myLevelPercent = model.user.levelPercent + self.myRunningProgressBar.setProgress(Float(model.user.levelPercent)/100, animated: false) + setMyRunningProgressPercentLabel(label: myRunnigProgressPercentLabel, model: model) + setMyRunningLevelLavel(label: myRunningLevelLavel, model: model) } + + private func setMyRunningProgressPercentLabel(label: UILabel, model: MyPageDto) { + let attributedString = NSMutableAttributedString(string: String(model.user.levelPercent), attributes: [.font: UIFont.b5, .foregroundColor: UIColor.g1]) + attributedString.append(NSAttributedString(string: " /100", attributes: [.font: UIFont.b5, .foregroundColor: UIColor.g2])) + label.attributedText = attributedString + } + + private func setMyRunningLevelLavel(label: UILabel, model: MyPageDto) { + let attributedString = NSMutableAttributedString(string: "LV ", attributes: [.font: UIFont.h5, .foregroundColor: UIColor.g1]) + attributedString.append(NSAttributedString(string: String(model.user.level), attributes: [.font: UIFont.h5, .foregroundColor: UIColor.g1])) + label.attributedText = attributedString + } + } // MARK: - @objc Function From 3d0a732f2ee49cb5add696e6582d836d4b48be37 Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Tue, 10 Jan 2023 23:12:44 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[Fix]=20#65=20-=20=EC=BD=94=EB=A9=98?= =?UTF-8?q?=ED=8A=B8=20=EB=B0=9B=EC=9D=80=20=EB=B6=80=EB=B6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift | 9 +++------ .../Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift | 8 ++------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift index 1811ea9b..c59b0e62 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift @@ -8,17 +8,14 @@ import Foundation // MARK: - MyPageDto + struct MyPageDto: Codable { let user: User } // MARK: - User + struct User: Codable { - let machineID, nickname, latestStamp: String + let machineId, nickname, latestStamp: String let level, levelPercent: Int - - enum CodingKeys: String, CodingKey { - case machineID = "machineId" - case nickname, latestStamp, level, levelPercent - } } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift index 08f8ec13..6ddd62b9 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift @@ -339,12 +339,8 @@ extension MyPageVC { if 200..<300 ~= status { do { let responseDto = try result.map(BaseResponse.self) - if responseDto.status == 200 { - guard let data = responseDto.data else { return } - self.setData(model: data) - } else { - self.showToast(message: responseDto.message) - } + guard let data = responseDto.data else { return } + self.setData(model: data) } catch { print(error.localizedDescription) }