diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index d4ed5b33..776fde5a 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 */; }; @@ -149,6 +151,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 = ""; }; @@ -406,6 +410,7 @@ isa = PBXGroup; children = ( CE10063D29680C8100FD31FB /* .gitkeep */, + A3F67AE1296D33AC001598A2 /* MyPageDto.swift */, ); path = MyPageDto; sourceTree = ""; @@ -737,6 +742,7 @@ isa = PBXGroup; children = ( CE10064329680CB400FD31FB /* .gitkeep */, + A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */, ); path = MyPageRouter; sourceTree = ""; @@ -1328,8 +1334,10 @@ CE40BB1C2967E4910030ABCA /* RunningWaitingVC.swift in Sources */, CE6B63D6296731F9003F900F /* ScrapCourseListView.swift in Sources */, CE6655F8295D90CF00C64E12 /* adjusted+.swift in Sources */, + A3F67AE4296D33E0001598A2 /* MyPageRouter.swift in Sources */, DAD5A3E2296D4C6500C8166B /* PickedMapListResponseDto.swift in Sources */, CE4545CB295D7AF4003201E1 /* SceneDelegate.swift in Sources */, + A3F67AE2296D33AC001598A2 /* MyPageDto.swift in Sources */, CE591EA1296D5EB5000FCBB3 /* PrivateCourseResponseDto.swift in Sources */, A3BC2F3F2964706100198261 /* UploadedCourseInfoCVC.swift in Sources */, CE6655FE295D912300C64E12 /* calculateTopInset.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..c59b0e62 --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift @@ -0,0 +1,21 @@ +// +// 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 +} 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..6ddd62b9 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift @@ -6,11 +6,19 @@ // import UIKit + import SnapKit import Then +import Moya final class MyPageVC: UIViewController { + // MARK: - Properties + + private var myPageProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) + // MARK: - UI Components private lazy var navibar = CustomNavigationBar(self, type: .title).setTitle("마이페이지") @@ -25,7 +33,6 @@ final class MyPageVC: UIViewController { } private let myProfileNameLabel = UILabel().then { - $0.text = "말랑콩떡" $0.textColor = .m1 $0.font = .h4 } @@ -44,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 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(0, animated: false) $0.progressTintColor = .m1 $0.trackTintColor = .m3 $0.layer.cornerRadius = 6 @@ -61,11 +64,7 @@ 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]) - 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)) @@ -89,6 +88,7 @@ final class MyPageVC: UIViewController { setNavigationBar() setUI() setLayout() + getMyPageInfo() } } @@ -153,6 +153,26 @@ extension MyPageVC { nicknameEditorVC.modalPresentationStyle = .overFullScreen self.present(nicknameEditorVC, animated: false) } + + private func setData(model: MyPageDto) { + self.myProfileNameLabel.text = model.user.nickname + 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 @@ -304,3 +324,35 @@ 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) + guard let data = responseDto.data else { return } + self.setData(model: data) + } 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 }