diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index d3c9d6f3..382e32b7 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -54,11 +54,14 @@ CE4545CD295D7AF4003201E1 /* TaBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE4545CC295D7AF4003201E1 /* TaBarController.swift */; }; CE4545D2295D7AF5003201E1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE4545D1295D7AF5003201E1 /* Assets.xcassets */; }; CE4545D5295D7AF5003201E1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE4545D3295D7AF5003201E1 /* LaunchScreen.storyboard */; }; + CE55BC11296D4EA600E8CD69 /* RunningRecordRequestDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE55BC10296D4EA600E8CD69 /* RunningRecordRequestDto.swift */; }; CE5645162961B72E000A2856 /* ImageLiterals.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5645152961B72E000A2856 /* ImageLiterals.swift */; }; CE58759E29601476005D967E /* LoadingIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE58759D29601476005D967E /* LoadingIndicator.swift */; }; CE5875A029601500005D967E /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE58759F29601500005D967E /* Toast.swift */; }; CE5875A2296015A2005D967E /* NetworkLoggerPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5875A1296015A2005D967E /* NetworkLoggerPlugin.swift */; }; CE5875A4296015D2005D967E /* Encodable+.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5875A3296015D2005D967E /* Encodable+.swift */; }; + CE591E9C296D4F69000FCBB3 /* RunningRecordResonseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE591E9B296D4F69000FCBB3 /* RunningRecordResonseDto.swift */; }; + CE591E9E296D5140000FCBB3 /* RunningRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE591E9D296D5140000FCBB3 /* RunningRouter.swift */; }; CE6655BF295D82E200C64E12 /* .gitkeep in Resources */ = {isa = PBXBuildFile; fileRef = CE6655BE295D82E200C64E12 /* .gitkeep */; }; CE6655C8295D849F00C64E12 /* StringLiterals.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6655C7295D849F00C64E12 /* StringLiterals.swift */; }; CE6655CA295D84DD00C64E12 /* UserDefaultKeyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6655C9295D84DD00C64E12 /* UserDefaultKeyList.swift */; }; @@ -151,12 +154,10 @@ CE10063C29680C7000FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10063D29680C8100FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10063E29680C8800FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; - CE10063F29680C9800FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064129680CA700FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064229680CAD00FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064329680CB400FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064429680CBC00FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; - CE10064529680CC300FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064D29680D2500FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064F29680D3300FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10065029680D3800FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; @@ -195,11 +196,14 @@ CE4545D1295D7AF5003201E1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; CE4545D4295D7AF5003201E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; CE4545D6295D7AF5003201E1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + CE55BC10296D4EA600E8CD69 /* RunningRecordRequestDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunningRecordRequestDto.swift; sourceTree = ""; }; CE5645152961B72E000A2856 /* ImageLiterals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLiterals.swift; sourceTree = ""; }; CE58759D29601476005D967E /* LoadingIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingIndicator.swift; sourceTree = ""; }; CE58759F29601500005D967E /* Toast.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toast.swift; sourceTree = ""; }; CE5875A1296015A2005D967E /* NetworkLoggerPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkLoggerPlugin.swift; sourceTree = ""; }; CE5875A3296015D2005D967E /* Encodable+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Encodable+.swift"; sourceTree = ""; }; + CE591E9B296D4F69000FCBB3 /* RunningRecordResonseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunningRecordResonseDto.swift; sourceTree = ""; }; + CE591E9D296D5140000FCBB3 /* RunningRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunningRouter.swift; sourceTree = ""; }; CE6655BE295D82E200C64E12 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE6655C0295D82F000C64E12 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE6655C1295D82F700C64E12 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; @@ -375,7 +379,8 @@ CE10063229680BEB00FD31FB /* RunningDto */ = { isa = PBXGroup; children = ( - CE10063F29680C9800FD31FB /* .gitkeep */, + CE55BC12296D4EB300E8CD69 /* RequestDto */, + CE55BC13296D4F3900E8CD69 /* ResponseDto */, ); path = RunningDto; sourceTree = ""; @@ -738,7 +743,7 @@ CE40BB2B296808500030ABCA /* RunningRouter */ = { isa = PBXGroup; children = ( - CE10064529680CC300FD31FB /* .gitkeep */, + CE591E9D296D5140000FCBB3 /* RunningRouter.swift */, ); path = RunningRouter; sourceTree = ""; @@ -773,6 +778,33 @@ path = "Runnect-iOS"; sourceTree = ""; }; + CE55BC0F296D4E5500E8CD69 /* RNUtils */ = { + isa = PBXGroup; + children = ( + CEC2A68F2962B06C00160BF7 /* convertLocationObject.swift */, + CE14677729658C7200DCEA1B /* Stopwatch.swift */, + CE9291282965E01D0010959C /* RNTimeFormatter.swift */, + CE3A53C4296C6017003D518C /* KeychainManager.swift */, + ); + path = RNUtils; + sourceTree = ""; + }; + CE55BC12296D4EB300E8CD69 /* RequestDto */ = { + isa = PBXGroup; + children = ( + CE55BC10296D4EA600E8CD69 /* RunningRecordRequestDto.swift */, + ); + path = RequestDto; + sourceTree = ""; + }; + CE55BC13296D4F3900E8CD69 /* ResponseDto */ = { + isa = PBXGroup; + children = ( + CE591E9B296D4F69000FCBB3 /* RunningRecordResonseDto.swift */, + ); + path = ResponseDto; + sourceTree = ""; + }; CE6655A8295D7F7D00C64E12 /* Presentation */ = { isa = PBXGroup; children = ( @@ -890,6 +922,7 @@ CE6655B1295D801700C64E12 /* Utils */ = { isa = PBXGroup; children = ( + CE55BC0F296D4E5500E8CD69 /* RNUtils */, CE6655F5295D90B600C64E12 /* addToolBar.swift */, CE6655F7295D90CF00C64E12 /* adjusted+.swift */, CE6655F9295D90E000C64E12 /* applyShadow.swift */, @@ -907,11 +940,7 @@ CE58759D29601476005D967E /* LoadingIndicator.swift */, CE58759F29601500005D967E /* Toast.swift */, CE6655C9295D84DD00C64E12 /* UserDefaultKeyList.swift */, - CEC2A68F2962B06C00160BF7 /* convertLocationObject.swift */, CE29D583296416D800F47542 /* caculateStatusBarHeight.swift */, - CE14677729658C7200DCEA1B /* Stopwatch.swift */, - CE9291282965E01D0010959C /* RNTimeFormatter.swift */, - CE3A53C4296C6017003D518C /* KeychainManager.swift */, ); path = Utils; sourceTree = ""; @@ -1221,6 +1250,7 @@ buildActionMask = 2147483647; files = ( CE40BB20296805F70030ABCA /* NetworkResult.swift in Sources */, + CE55BC11296D4EA600E8CD69 /* RunningRecordRequestDto.swift in Sources */, CE665604295D91B100C64E12 /* makeAlert.swift in Sources */, A3BC2F2F2962C40A00198261 /* UploadedCourseInfoVC.swift in Sources */, CE6655EA295D88B200C64E12 /* UITabBar+.swift in Sources */, @@ -1286,6 +1316,7 @@ CEB841702963360800BF8080 /* CountDownVC.swift in Sources */, CE320F38296C8FAB009F89A7 /* CourseDrawingResponseData.swift in Sources */, CE18E894296C79B900FEB569 /* CourseDrawingRequestDto.swift in Sources */, + CE591E9E296D5140000FCBB3 /* RunningRouter.swift in Sources */, DA20D84E2966A9B300F1581F /* CourseSearchVC.swift in Sources */, CE1006572968230800FD31FB /* DepartureLocationModel.swift in Sources */, CE6655EC295D88D000C64E12 /* UITableView+.swift in Sources */, @@ -1329,6 +1360,7 @@ CE9291252965C9FB0010959C /* CourseDetailInfoView.swift in Sources */, CE665600295D915D00C64E12 /* getClassName.swift in Sources */, A3BC2F2D2962C3F200198261 /* ActivityRecordInfoVC.swift in Sources */, + CE591E9C296D4F69000FCBB3 /* RunningRecordResonseDto.swift in Sources */, CE6655FC295D90F500C64E12 /* calculatePastTime.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Runnect-iOS/Runnect-iOS/Global/Utils/KeychainManager.swift b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/KeychainManager.swift similarity index 100% rename from Runnect-iOS/Runnect-iOS/Global/Utils/KeychainManager.swift rename to Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/KeychainManager.swift diff --git a/Runnect-iOS/Runnect-iOS/Global/Utils/RNTimeFormatter.swift b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/RNTimeFormatter.swift similarity index 100% rename from Runnect-iOS/Runnect-iOS/Global/Utils/RNTimeFormatter.swift rename to Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/RNTimeFormatter.swift diff --git a/Runnect-iOS/Runnect-iOS/Global/Utils/Stopwatch.swift b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/Stopwatch.swift similarity index 100% rename from Runnect-iOS/Runnect-iOS/Global/Utils/Stopwatch.swift rename to Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/Stopwatch.swift diff --git a/Runnect-iOS/Runnect-iOS/Global/Utils/convertLocationObject.swift b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/convertLocationObject.swift similarity index 100% rename from Runnect-iOS/Runnect-iOS/Global/Utils/convertLocationObject.swift rename to Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/convertLocationObject.swift diff --git a/Runnect-iOS/Runnect-iOS/Global/Utils/Toast.swift b/Runnect-iOS/Runnect-iOS/Global/Utils/Toast.swift index 6a421642..d1c1887a 100644 --- a/Runnect-iOS/Runnect-iOS/Global/Utils/Toast.swift +++ b/Runnect-iOS/Runnect-iOS/Global/Utils/Toast.swift @@ -44,7 +44,7 @@ public class Toast { toastContainer.snp.makeConstraints { $0.centerX.equalToSuperview() $0.bottom.equalToSuperview().inset(safeAreaBottomInset+40) - $0.width.equalTo(100) + $0.width.equalTo(200) $0.height.equalTo(44) } diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/RunningDto/.gitkeep b/Runnect-iOS/Runnect-iOS/Network/Dto/RunningDto/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/RunningDto/RequestDto/RunningRecordRequestDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/RunningDto/RequestDto/RunningRecordRequestDto.swift new file mode 100644 index 00000000..8a9834da --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/RunningDto/RequestDto/RunningRecordRequestDto.swift @@ -0,0 +1,16 @@ +// +// RunningRecordRequestDto.swift +// Runnect-iOS +// +// Created by sejin on 2023/01/10. +// + +import Foundation + +// MARK: - RunningRecordRequestDto + +struct RunningRecordRequestDto: Codable { + let courseId: Int + let publicCourseId: Int? + let title, time, pace: String +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/RunningDto/ResponseDto/RunningRecordResonseDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/RunningDto/ResponseDto/RunningRecordResonseDto.swift new file mode 100644 index 00000000..d77c0124 --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/RunningDto/ResponseDto/RunningRecordResonseDto.swift @@ -0,0 +1,21 @@ +// +// RunningRecordResonseDto.swift +// Runnect-iOS +// +// Created by sejin on 2023/01/10. +// + +import Foundation + +// MARK: - RunningRecordResonseDto + +struct RunningRecordResonseDto: Codable { + let record: RunningRecordResonseData +} + +// MARK: - RunningRecordResonseData + +struct RunningRecordResonseData: Codable { + let id: Int + let createdAt: String +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift b/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift index 512ac56f..a61b152d 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift @@ -15,4 +15,27 @@ struct RunningModel { var locations: [NMGLatLng] var distance: String? var pathImage: UIImage? + var totalTime: Int? + + /// HH:MM:SS 형식으로 반환 + func getFormattedTotalTime() -> String? { + guard let totalTime = self.totalTime else { return nil } + return RNTimeFormatter.secondsToHHMMSS(seconds: totalTime) + } + + /// mm'ss'' 형식으로 반환 + func getFormattedAveragePage() -> String? { + guard let averagePaceSecondsInt = getIntPace() else { return nil } + let formattedAveragePace = "\(averagePaceSecondsInt / 60)'\(averagePaceSecondsInt % 60)''" + return formattedAveragePace + } + + // Pace를 Int(초)형식으로 반환 + func getIntPace() -> Int? { + guard let distance = distance, let totalTime = self.totalTime else { return nil } + guard let floatDistance = Float(distance) else { return nil } + let averagePaceSeconds = round(Float(totalTime) / floatDistance) + let averagePaceSecondsInt = Int(averagePaceSeconds) + return averagePaceSecondsInt + } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/RunningRouter/.gitkeep b/Runnect-iOS/Runnect-iOS/Network/Router/RunningRouter/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/RunningRouter/RunningRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/RunningRouter/RunningRouter.swift new file mode 100644 index 00000000..409b78bc --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Router/RunningRouter/RunningRouter.swift @@ -0,0 +1,56 @@ +// +// RunningRouter.swift +// Runnect-iOS +// +// Created by sejin on 2023/01/10. +// + +import Foundation + +import Moya + +enum RunningRouter { + case recordRunning(param: RunningRecordRequestDto) +} + +extension RunningRouter: 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 .recordRunning: + return "/record" + } + } + + var method: Moya.Method { + switch self { + case .recordRunning: + return .post + } + } + + var task: Moya.Task { + switch self { + case .recordRunning(let param): + do { + return .requestParameters(parameters: try param.asParameter(), encoding: JSONEncoding.default) + } catch { + fatalError(error.localizedDescription) + } + } + } + + var headers: [String : String]? { + switch self { + case .recordRunning: + return Config.headerWithDeviceId + } + } +} diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift index 6fe848ec..af708be9 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift @@ -170,9 +170,10 @@ extension CourseDrawingVC { alertVC.rightButtonTapped.sink { [weak self] _ in guard let self = self else { return } let countDownVC = CountDownVC() - let runningModel = RunningModel(locations: self.mapView.getMarkersLatLng(), - distance: self.distanceLabel.text, - pathImage: self.pathImage) + let runningModel = RunningModel(courseId: courseId, + locations: self.mapView.getMarkersLatLng(), + distance: self.distanceLabel.text, + pathImage: self.pathImage) countDownVC.setData(runningModel: runningModel) self.navigationController?.pushViewController(countDownVC, animated: true) alertVC.dismiss(animated: true) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunTrackingVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunTrackingVC.swift index 41d03747..0a50d010 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunTrackingVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunTrackingVC.swift @@ -184,17 +184,12 @@ extension RunTrackingVC { } private func pushToRunningRecordVC() { - guard let distance = Float(self.distance) else { return } - guard let runningModel = self.runningModel else { return } - let averagePaceSeconds = round(Float(self.totalTime) / distance) - let averagePaceSecondsInt = Int(averagePaceSeconds) - let formatedAveragePace = "\(averagePaceSecondsInt / 60)'\(averagePaceSecondsInt % 60)''" + guard var runningModel = self.runningModel else { return } + + runningModel.totalTime = self.totalTime let runningRecordVC = RunningRecordVC() - runningRecordVC.setData(distance: self.distance, - totalTime: RNTimeFormatter.secondsToHHMMSS(seconds: self.totalTime), - averagePace: formatedAveragePace, - pathImage: runningModel.pathImage) + runningRecordVC.setData(runningModel: runningModel) self.navigationController?.pushViewController(runningRecordVC, animated: true) } } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunningRecordVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunningRecordVC.swift index 9ddfff8b..bfc2c88c 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunningRecordVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunningRecordVC.swift @@ -7,10 +7,18 @@ import UIKit +import Moya + final class RunningRecordVC: UIViewController { // MARK: - Properties + private var runningModel: RunningModel? + + private let runningProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) + private let courseTitleMaxLength = 20 // MARK: - UI Components @@ -94,6 +102,8 @@ final class RunningRecordVC: UIViewController { extension RunningRecordVC { private func setAddTarget() { self.courseTitleTextField.addTarget(self, action: #selector(textFieldTextDidChange), for: .editingChanged) + + self.saveButton.addTarget(self, action: #selector(saveButtonDidTap), for: .touchUpInside) } // 키보드가 올라오면 scrollView 위치 조정 @@ -118,11 +128,12 @@ extension RunningRecordVC { view.addGestureRecognizer(tap) } - func setData(distance: String, totalTime: String, averagePace: String, pathImage: UIImage?) { - self.distanceStatsView.setAttributedStats(stats: distance) - self.totalTimeStatsView.setStats(stats: totalTime) - self.averagePaceStatsView.setStats(stats: averagePace) - self.courseImageView.image = pathImage + func setData(runningModel: RunningModel) { + self.runningModel = runningModel + self.distanceStatsView.setAttributedStats(stats: runningModel.distance ?? "0.0") + self.totalTimeStatsView.setStats(stats: runningModel.getFormattedTotalTime() ?? "00:00:00") + self.averagePaceStatsView.setStats(stats: runningModel.getFormattedAveragePage() ?? "0'00''") + self.courseImageView.image = runningModel.pathImage } } @@ -161,6 +172,10 @@ extension RunningRecordVC { scrollView.contentInset = contentInset scrollView.scrollIndicatorInsets = contentInset } + + @objc private func saveButtonDidTap() { + self.recordRunning() + } } // MARK: - UI & Layout @@ -260,3 +275,42 @@ extension RunningRecordVC { courseTitleTextField.addBottomBorder(height: 2) } } + +// MARK: - Network + +extension RunningRecordVC { + private func recordRunning() { + guard let runningModel = self.runningModel else { return } + guard let courseId = runningModel.courseId else { return } + guard let titleText = courseTitleTextField.text else { return } + guard let time = runningModel.getFormattedTotalTime() else { return } + guard let secondsPerKm = runningModel.getIntPace() else { return } + let pace = RNTimeFormatter.secondsToHHMMSS(seconds: secondsPerKm) + + let requestDto = RunningRecordRequestDto(courseId: courseId, + publicCourseId: runningModel.publicCourseId, + title: titleText, + time: time, + pace: pace) + + LoadingIndicator.showLoading() + runningProvider.request(.recordRunning(param: requestDto)) { [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 { + self.navigationController?.popToRootViewController(animated: true) + } + if status >= 400 { + print("400 error") + self.showNetworkFailureToast() + } + case .failure(let error): + print(error.localizedDescription) + self.showNetworkFailureToast() + } + } + } +}