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
11 changes: 4 additions & 7 deletions Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
CEEC6B492961C5E200D00E1E /* SplashVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B482961C5E200D00E1E /* SplashVC.swift */; };
CEEC6B4B2961D89700D00E1E /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */; };
CEF3CD98296D63B9002723A1 /* CourseStorageRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF3CD97296D63B9002723A1 /* CourseStorageRouter.swift */; };
CEF3CD9A296DB305002723A1 /* CourseDetailResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */; };
DA20D847296697A600F1581F /* MyCourseSelectVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D846296697A600F1581F /* MyCourseSelectVC.swift */; };
DA20D849296697B400F1581F /* CourseUploadVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D848296697B400F1581F /* CourseUploadVC.swift */; };
DA20D84E2966A9B300F1581F /* CourseSearchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */; };
Expand Down Expand Up @@ -158,13 +159,8 @@
CE0C23782966D6AF00B45063 /* ViewPager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPager.swift; sourceTree = "<group>"; };
CE0D9FD229648DA300CEB5CD /* CustomAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAlertVC.swift; sourceTree = "<group>"; };
CE10063929680C5700FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10063B29680C6800FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10063C29680C7000FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10063D29680C8100FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10063E29680C8800FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10063F29680C9800FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10064129680CA700FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10064229680CAD00FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10064329680CB400FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10064429680CBC00FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10064D29680D2500FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
Expand Down Expand Up @@ -215,7 +211,6 @@
CE591E9D296D5140000FCBB3 /* RunningRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunningRouter.swift; sourceTree = "<group>"; };
CE591EA0296D5EB5000FCBB3 /* PrivateCourseResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivateCourseResponseDto.swift; sourceTree = "<group>"; };
CE6655BE295D82E200C64E12 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE6655C0295D82F000C64E12 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE6655C1295D82F700C64E12 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE6655C5295D83B700C64E12 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE6655C7295D849F00C64E12 /* StringLiterals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringLiterals.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -283,6 +278,7 @@
CEEC6B482961C5E200D00E1E /* SplashVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashVC.swift; sourceTree = "<group>"; };
CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = "<group>"; };
CEF3CD97296D63B9002723A1 /* CourseStorageRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseStorageRouter.swift; sourceTree = "<group>"; };
CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailResponseDto.swift; sourceTree = "<group>"; };
DA20D846296697A600F1581F /* MyCourseSelectVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyCourseSelectVC.swift; sourceTree = "<group>"; };
DA20D848296697B400F1581F /* CourseUploadVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseUploadVC.swift; sourceTree = "<group>"; };
DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseSearchVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -816,6 +812,7 @@
isa = PBXGroup;
children = (
CE591E9B296D4F69000FCBB3 /* RunningRecordResonseDto.swift */,
CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */,
);
path = ResponseDto;
sourceTree = "<group>";
Expand Down Expand Up @@ -903,7 +900,6 @@
CE40BB292968083B0030ABCA /* MyPageRouter */,
CE40BB2A296808440030ABCA /* CourseDetailRouter */,
CE40BB2B296808500030ABCA /* RunningRouter */,
CE6655C0295D82F000C64E12 /* .gitkeep */,
);
path = Router;
sourceTree = "<group>";
Expand Down Expand Up @@ -1362,6 +1358,7 @@
CEC2A6902962B06C00160BF7 /* convertLocationObject.swift in Sources */,
CEC2A6852961F92C00160BF7 /* CustomButton.swift in Sources */,
CE6B63D3296725E6003F900F /* CourseListCVC.swift in Sources */,
CEF3CD9A296DB305002723A1 /* CourseDetailResponseDto.swift in Sources */,
CE29D584296416D800F47542 /* caculateStatusBarHeight.swift in Sources */,
CE66560C295D928300C64E12 /* setRootViewController.swift in Sources */,
CE6655D9295D871B00C64E12 /* URL+.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct PrivateCourseResponseDto: Codable {
struct PrivateCourse: Codable {
let id: Int
let image, createdAt: String
let distance: Float?
let distance: String?
let path: [[Double]]?
let departure: PrivateCourseDeparture
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CourseDetailResponseDto.swift
// Runnect-iOS
//
// Created by sejin on 2023/01/10.
//

import Foundation

typealias Course = PrivateCourse
typealias CourseDeparture = PrivateCourseDeparture

// MARK: - CourseDetailResponseDto

struct CourseDetailResponseDto: Codable {
let course: Course
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ struct DepartureLocationModel {
let departureAddress: String
let latitude: String
let longitude: String

var region: String {
departureAddress.split(separator: " ").map {String($0)}[0]
}

var city: String {
departureAddress.split(separator: " ").map {String($0)}[1]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ struct RunningModel {
var locations: [NMGLatLng]
var distance: String?
var pathImage: UIImage?
var imageUrl: String?
var totalTime: Int?
var region: String?
var city: String?

/// HH:MM:SS 형식으로 반환
func getFormattedTotalTime() -> String? {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Moya

enum RunningRouter {
case recordRunning(param: RunningRecordRequestDto)
case getCourseDetail(courseId: Int)
}

extension RunningRouter: TargetType {
Expand All @@ -26,13 +27,17 @@ extension RunningRouter: TargetType {
switch self {
case .recordRunning:
return "/record"
case .getCourseDetail(let courseId):
return "/course/detail/\(courseId)"
}
}

var method: Moya.Method {
switch self {
case .recordRunning:
return .post
case .getCourseDetail:
return .get
}
}

Expand All @@ -44,12 +49,14 @@ extension RunningRouter: TargetType {
} catch {
fatalError(error.localizedDescription)
}
case .getCourseDetail:
return .requestPlain
}
}

var headers: [String: String]? {
switch self {
case .recordRunning:
case .recordRunning, .getCourseDetail:
return Config.headerWithDeviceId
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ extension CourseDrawingVC {
let runningModel = RunningModel(courseId: courseId,
locations: self.mapView.getMarkersLatLng(),
distance: self.distanceLabel.text,
pathImage: self.pathImage)
pathImage: self.pathImage,
region: self.departureLocationModel?.region,
city: self.departureLocationModel?.city)
countDownVC.setData(runningModel: runningModel)
self.navigationController?.pushViewController(countDownVC, animated: true)
alertVC.dismiss(animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ extension CourseStorageVC {
privateCourseListView.cellDidTapped.sink { [weak self] index in
guard let self = self else { return }
let runningWaitingVC = RunningWaitingVC()
runningWaitingVC.setData(courseId: self.privateCourseList[index].id, publicCourseId: nil)
runningWaitingVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(runningWaitingVC, animated: true)
}.store(in: cancelBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ extension CountDownVC {
extension CountDownVC {
private func setUI() {
view.backgroundColor = .m1
self.navigationController?.isNavigationBarHidden = true
}

private func setLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ extension RunningRecordVC {
self.totalTimeStatsView.setStats(stats: runningModel.getFormattedTotalTime() ?? "00:00:00")
self.averagePaceStatsView.setStats(stats: runningModel.getFormattedAveragePage() ?? "0'00''")
self.courseImageView.image = runningModel.pathImage

guard let region = runningModel.region, let city = runningModel.city else { return }
self.departureInfoView.setDescriptionText(description: "\(region) \(city)")

guard let imageUrl = runningModel.imageUrl else { return }
self.courseImageView.setImage(with: imageUrl)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@

import UIKit

import NMapsMap
import Moya

final class RunningWaitingVC: UIViewController {

// MARK: - Properties

private var courseId: Int?
private var publicCourseId: Int?
private var courseModel: Course?

private let runningProvider = MoyaProvider<RunningRouter>(
plugins: [NetworkLoggerPlugin(verbose: true)]
)

// MARK: - UI Components

private lazy var naviBar = CustomNavigationBar(self, type: .titleWithLeftButton)
Expand Down Expand Up @@ -59,6 +72,26 @@ final class RunningWaitingVC: UIViewController {
// MARK: - Methods

extension RunningWaitingVC {
func setData(courseId: Int, publicCourseId: Int?) {
self.courseId = courseId
self.publicCourseId = publicCourseId

getCourseDetail(courseId: courseId)
}

private func setCourseData(courseModel: Course) {
self.courseModel = courseModel

guard let path = courseModel.path, let distance = courseModel.distance else { return }
let locations = path.map { NMGLatLng(lat: $0[0], lng: $0[1]) }
self.makePath(locations: locations)
self.distanceLabel.text = String(distance)
}

func makePath(locations: [NMGLatLng]) {
self.mapView.makeMarkersWithStartMarker(at: locations, moveCameraToStartMarker: true)
}

private func setAddTarget() {
self.startButton.addTarget(self, action: #selector(startButtonDidTap), for: .touchUpInside)
}
Expand All @@ -68,15 +101,17 @@ extension RunningWaitingVC {

extension RunningWaitingVC {
@objc private func startButtonDidTap() {
if self.distanceLabel.text == "0.0" {
return
}
guard let courseModel = self.courseModel, self.distanceLabel.text != "0.0" else { return }

let countDownVC = CountDownVC()

let runningModel = RunningModel(locations: self.mapView.getMarkersLatLng(),
let runningModel = RunningModel(courseId: self.courseId,
publicCourseId: self.publicCourseId,
locations: self.mapView.getMarkersLatLng(),
distance: self.distanceLabel.text,
pathImage: UIImage())
imageUrl: courseModel.image,
region: courseModel.departure.region,
city: courseModel.departure.city)

countDownVC.setData(runningModel: runningModel)
self.navigationController?.pushViewController(countDownVC, animated: true)
}
Expand Down Expand Up @@ -139,3 +174,36 @@ extension RunningWaitingVC {
}
}
}

// MARK: - Network

extension RunningWaitingVC {
private func getCourseDetail(courseId: Int) {
LoadingIndicator.showLoading()

runningProvider.request(.getCourseDetail(courseId: courseId)) { [weak self] response in
guard let self = self else { return }
LoadingIndicator.hideLoading()
switch response {
case .success(let result):
let status = result.statusCode
if 200..<300 ~= status {
do {
let responseDto = try result.map(BaseResponse<CourseDetailResponseDto>.self)
guard let data = responseDto.data else { return }
self.setCourseData(courseModel: data.course)
} catch {
print(error.localizedDescription)
}
}
if status >= 400 {
print("400 error")
self.showNetworkFailureToast()
}
case .failure(let error):
print(error.localizedDescription)
self.showNetworkFailureToast()
}
}
}
}