Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -149,6 +151,8 @@
A3BC2F3E2964706100198261 /* UploadedCourseInfoCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadedCourseInfoCVC.swift; sourceTree = "<group>"; };
A3BC2F4029667A0D00198261 /* NicknameEditorVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameEditorVC.swift; sourceTree = "<group>"; };
A3BC2F422966A93100198261 /* CourseDetailVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailVC.swift; sourceTree = "<group>"; };
A3F67AE1296D33AC001598A2 /* MyPageDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageDto.swift; sourceTree = "<group>"; };
A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageRouter.swift; sourceTree = "<group>"; };
CE0C23732966D62A00B45063 /* PagedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagedView.swift; sourceTree = "<group>"; };
CE0C23762966D64D00B45063 /* PageCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageCVC.swift; sourceTree = "<group>"; };
CE0C23782966D6AF00B45063 /* ViewPager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -406,6 +410,7 @@
isa = PBXGroup;
children = (
CE10063D29680C8100FD31FB /* .gitkeep */,
A3F67AE1296D33AC001598A2 /* MyPageDto.swift */,
);
path = MyPageDto;
sourceTree = "<group>";
Expand Down Expand Up @@ -737,6 +742,7 @@
isa = PBXGroup;
children = (
CE10064329680CB400FD31FB /* .gitkeep */,
A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */,
);
path = MyPageRouter;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
21 changes: 21 additions & 0 deletions Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/MyPageDto.swift
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가능하다면 MARK 구문 밑에 한줄은 여백으로 남겨주세요!


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
}
}
}
78 changes: 65 additions & 13 deletions Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/MyPageVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("마이페이지")
Expand All @@ -25,7 +33,6 @@ final class MyPageVC: UIViewController {
}

private let myProfileNameLabel = UILabel().then {
$0.text = "말랑콩떡"
$0.textColor = .m1
$0.font = .h4
}
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -89,6 +88,7 @@ final class MyPageVC: UIViewController {
setNavigationBar()
setUI()
setLayout()
getMyPageInfo()
}
}

Expand Down Expand Up @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -304,3 +324,35 @@ extension MyPageVC {
}
}
}

// MARK: - Network

extension MyPageVC {
func getMyPageInfo() {
LoadingIndicator.showLoading()
myPageProvider.request(.getMyPageInfo) { [weak self] response in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weak self 를 왜 사용하는지에 대해서도 깊게 공부해보면 좋아요!! Swift의 핵심 특징중 하나인 ARC에 관련된 내용이라 나중에 시간 나면 꼭꼭 공부해보면 좋을 거 같아요~!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down