-
Notifications
You must be signed in to change notification settings - Fork 6
[Feat] #65 - 마이페이지 API 연결 #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "feat/#65-\uB9C8\uC774\uD398\uC774\uC9C0-API-\uC5F0\uACB0"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,19 @@ | |
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| import SnapKit | ||
| import Then | ||
| import Moya | ||
|
|
||
| final class MyPageVC: UIViewController { | ||
|
|
||
| // MARK: - Properties | ||
|
|
||
| private var myPageProvider = MoyaProvider<MyPageRouter>( | ||
| 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) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수로 잘 분리해서 만들었네요~~! 👍 |
||
| 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. weak self 를 왜 사용하는지에 대해서도 깊게 공부해보면 좋아요!! Swift의 핵심 특징중 하나인 ARC에 관련된 내용이라 나중에 시간 나면 꼭꼭 공부해보면 좋을 거 같아요~!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! 그냥 따라했어욥..ㅋ |
||
| 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<MyPageDto>.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() | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
가능하다면 MARK 구문 밑에 한줄은 여백으로 남겨주세요!