From 95de6e2d400ac74885c6768964f5cbbc5b7fe598 Mon Sep 17 00:00:00 2001 From: yeonwoo Date: Thu, 12 Jan 2023 02:36:32 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Feat]=20#81=20-=20=EC=BD=94=EC=8A=A4?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=ED=95=98=EA=B8=B0=20API=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS.xcodeproj/project.pbxproj | 8 ++ .../Extension/Foundation+/Encodable+.swift | 1 - .../CourseUploadingRequestDto.swift | 15 ++++ .../Model/RunningModel/RunningModel.swift | 1 + .../CourseUploadingRouter.swift | 53 ++++++++++++ .../Views/VC/CourseSearchVC.swift | 3 +- .../Views/VC/CourseUploadVC.swift | 82 +++++++++++++++++-- 7 files changed, 153 insertions(+), 10 deletions(-) create mode 100644 Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/RequestDto/CourseUploadingRequestDto.swift create mode 100644 Runnect-iOS/Runnect-iOS/Network/Router/CourseDiscoveryRouter/CourseUploadingRouter.swift diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index 3f4fc566..d8422ca1 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -132,6 +132,8 @@ DA20D849296697B400F1581F /* CourseUploadVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D848296697B400F1581F /* CourseUploadVC.swift */; }; DA20D84E2966A9B300F1581F /* CourseSearchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */; }; DA97A02F296DC3300086760E /* CourseSearchingRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA97A02E296DC3300086760E /* CourseSearchingRouter.swift */; }; + DA97A033296E65D80086760E /* CourseUploadingRequestDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA97A032296E65D80086760E /* CourseUploadingRequestDto.swift */; }; + DA97A035296E685C0086760E /* CourseUploadingRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA97A034296E685C0086760E /* CourseUploadingRouter.swift */; }; DAD5A3D8296C6D9600C8166B /* AdImageCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD5A3D7296C6D9600C8166B /* AdImageCollectionViewCell.swift */; }; DAD5A3DA296C6DA500C8166B /* TitleCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD5A3D9296C6DA500C8166B /* TitleCollectionViewCell.swift */; }; DAD5A3DC296C6DB800C8166B /* MapCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD5A3DB296C6DB800C8166B /* MapCollectionViewCell.swift */; }; @@ -284,6 +286,8 @@ DA20D848296697B400F1581F /* CourseUploadVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseUploadVC.swift; sourceTree = ""; }; DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseSearchVC.swift; sourceTree = ""; }; DA97A02E296DC3300086760E /* CourseSearchingRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseSearchingRouter.swift; sourceTree = ""; }; + DA97A032296E65D80086760E /* CourseUploadingRequestDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseUploadingRequestDto.swift; sourceTree = ""; }; + DA97A034296E685C0086760E /* CourseUploadingRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseUploadingRouter.swift; sourceTree = ""; }; DAD5A3D7296C6D9600C8166B /* AdImageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdImageCollectionViewCell.swift; sourceTree = ""; }; DAD5A3D9296C6DA500C8166B /* TitleCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleCollectionViewCell.swift; sourceTree = ""; }; DAD5A3DB296C6DB800C8166B /* MapCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapCollectionViewCell.swift; sourceTree = ""; }; @@ -734,6 +738,7 @@ children = ( DAD5A3E3296D526D00C8166B /* CourseDiscoveryRouter.swift */, DA97A02E296DC3300086760E /* CourseSearchingRouter.swift */, + DA97A034296E685C0086760E /* CourseUploadingRouter.swift */, ); path = CourseDiscoveryRouter; sourceTree = ""; @@ -1136,6 +1141,7 @@ DA97A029296DC2020086760E /* RequestDto */ = { isa = PBXGroup; children = ( + DA97A032296E65D80086760E /* CourseUploadingRequestDto.swift */, ); path = RequestDto; sourceTree = ""; @@ -1295,6 +1301,7 @@ CE9291272965D0ED0010959C /* StatsInfoView.swift in Sources */, CEC2A68729629B9B00160BF7 /* SignInVC.swift in Sources */, CE665602295D918000C64E12 /* JsonCoder.swift in Sources */, + DA97A033296E65D80086760E /* CourseUploadingRequestDto.swift in Sources */, CE4545CD295D7AF4003201E1 /* TaBarController.swift in Sources */, CE6655F4295D898400C64E12 /* UIViewController+.swift in Sources */, CE320F36296C8EAB009F89A7 /* CourseDrawingRouter.swift in Sources */, @@ -1400,6 +1407,7 @@ A3BC2F382963CE3700198261 /* ActivityRecordInfoModel.swift in Sources */, CE6655E6295D887F00C64E12 /* UIStackView+.swift in Sources */, A3BC2F34296303A600198261 /* GoalRewardInfoCVC.swift in Sources */, + DA97A035296E685C0086760E /* CourseUploadingRouter.swift in Sources */, CEB8416E2962C45300BF8080 /* LocationSearchResultTVC.swift in Sources */, CE6655CA295D84DD00C64E12 /* UserDefaultKeyList.swift in Sources */, CE6655F2295D894D00C64E12 /* UIView+.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Global/Extension/Foundation+/Encodable+.swift b/Runnect-iOS/Runnect-iOS/Global/Extension/Foundation+/Encodable+.swift index 00eb724d..e3278409 100644 --- a/Runnect-iOS/Runnect-iOS/Global/Extension/Foundation+/Encodable+.swift +++ b/Runnect-iOS/Runnect-iOS/Global/Extension/Foundation+/Encodable+.swift @@ -17,7 +17,6 @@ extension Encodable { as? [String: Any] else { throw NSError() } - return dictionary } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/RequestDto/CourseUploadingRequestDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/RequestDto/CourseUploadingRequestDto.swift new file mode 100644 index 00000000..17a8ca8c --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/RequestDto/CourseUploadingRequestDto.swift @@ -0,0 +1,15 @@ +// +// CourseUploadingRequestDto.swift +// Runnect-iOS +// +// Created by YEONOO on 2023/01/11. +// + +import Foundation + +// MARK: - CourseUploadingRequestDto + +struct CourseUploadingRequestDto: Codable { + let courseID: Int + let title, description: String +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift b/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift index b9aa6ce0..e6cbb283 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift @@ -19,6 +19,7 @@ struct RunningModel { var totalTime: Int? var region: String? var city: String? + var discription: String? /// HH:MM:SS 형식으로 반환 func getFormattedTotalTime() -> String? { diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/CourseDiscoveryRouter/CourseUploadingRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/CourseDiscoveryRouter/CourseUploadingRouter.swift new file mode 100644 index 00000000..c0a0297b --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Router/CourseDiscoveryRouter/CourseUploadingRouter.swift @@ -0,0 +1,53 @@ +// +// CourseUploadingRouter.swift +// Runnect-iOS +// +// Created by YEONOO on 2023/01/11. +// + +import Foundation + +import Moya + +enum CourseUploadingRouter { + case courseUploadingData(param: CourseUploadingRequestDto) +} + +extension CourseUploadingRouter: 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 .courseUploadingData: + return "/public-course" + } + } + + var method: Moya.Method { + switch self { + case .courseUploadingData: + return .post + } + } + + var task: Moya.Task { + switch self { + case .courseUploadingData(param: let param): + return .requestParameters(parameters: try! param.asParameter(), encoding: JSONEncoding.default) + } + } + + var headers: [String: String]? { + switch self { + case .courseUploadingData: + return Config.headerWithDeviceId + } + } + +} diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseSearchVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseSearchVC.swift index 96e0dc3c..c30221fb 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseSearchVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseSearchVC.swift @@ -16,7 +16,8 @@ final class CourseSearchVC: UIViewController { // MARK: - Properties private let CourseSearchingRouter = MoyaProvider( - plugins: [NetworkLoggerPlugin(verbose: true)]) + plugins: [NetworkLoggerPlugin(verbose: true)] + ) private var courseList = [PublicCourse]() diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift index 80ef6320..6c6f4aca 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift @@ -9,11 +9,17 @@ import UIKit import SnapKit import Then +import Moya -class CourseUploadVC: UIViewController { +final class CourseUploadVC: UIViewController { // MARK: - Properties + private var runningModel: RunningModel? + private let CourseUploadingProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) private let courseTitleMaxLength = 20 + // MARK: - UI Components private lazy var navibar = CustomNavigationBar(self, type: .titleWithLeftButton).setTitle("코스 업로드") @@ -76,8 +82,8 @@ class CourseUploadVC: UIViewController { extension CourseUploadVC { private func setAddTarget() { - self.uploadButton.addTarget(self, action: #selector(pushToCourseDiscoveryVC), for: .touchUpInside) self.courseTitleTextField.addTarget(self, action: #selector(textFieldTextDidChange), for: .editingChanged) + self.uploadButton.addTarget(self, action: #selector(uploadButtonDidTap), for: .touchUpInside) } // 키보드가 올라오면 scrollView 위치 조정 @@ -114,20 +120,34 @@ extension CourseUploadVC { name: UIResponder.keyboardWillHideNotification, object: nil) } + + func setData(runningModel: RunningModel) { + self.runningModel = runningModel + self.mapImageView.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.mapImageView.setImage(with: imageUrl) + } + + private func pushToCourseDiscoveryVC() { + let nextVC = CourseDiscoveryVC() + self.navigationController?.pushViewController(nextVC, animated: true) + + } } - // MARK: - @objc Function extension CourseUploadVC { - @objc private func pushToCourseDiscoveryVC() { - let nextVC = CourseDiscoveryVC() - self.navigationController?.pushViewController(nextVC, animated: true) - } +// @objc private func pushToCourseDiscoveryVC() { +// let nextVC = CourseDiscoveryVC() +// self.navigationController?.pushViewController(nextVC, animated: true) +// } @objc private func textFieldTextDidChange() { guard let text = courseTitleTextField.text else { return } - + if text.count > courseTitleMaxLength { let index = text.index(text.startIndex, offsetBy: courseTitleMaxLength) let newString = text[text.startIndex...self) + if responseDto.status == 200 { + self.pushToCourseDiscoveryVC() + } else { + self.showToast(message: responseDto.message) + } + } catch { + print(error.localizedDescription) + } + } + if status >= 400 { + print("400 error") + self.showNetworkFailureToast() + } + case .failure(let error): + print(error.localizedDescription) + self.showNetworkFailureToast() + } + } + } +} From b03d9a925ba8f22082ee3f7ba4ce495f2e2b0900 Mon Sep 17 00:00:00 2001 From: yeonwoo Date: Thu, 12 Jan 2023 03:32:38 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[Fix]=20#81=20-=20api=20=EB=B6=80=EB=B6=84?= =?UTF-8?q?=20=EC=95=BD=EA=B0=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CourseDiscovery/Views/VC/CourseUploadVC.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift index a022f79a..efb0a92e 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift @@ -15,7 +15,9 @@ class CourseUploadVC: UIViewController { // MARK: - Properties private var runningModel: RunningModel? - + private let courseUploadingProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) private var courseModel: Course? private let courseTitleMaxLength = 20 @@ -347,7 +349,7 @@ extension CourseUploadVC { let requsetDto = CourseUploadingRequestDto(courseID: courseId, title: titletext, description: descriptiontext) LoadingIndicator.showLoading() - CourseUploadingProvider.request(.courseUploadingData(param: requsetDto)) { [weak self] response in + courseUploadingProvider.request(.courseUploadingData(param: requsetDto)) { [weak self] response in LoadingIndicator.hideLoading() guard let self = self else { return } switch response { From 09897785205ef7c008c4c992130243e29427bc14 Mon Sep 17 00:00:00 2001 From: yeonwoo Date: Thu, 12 Jan 2023 14:26:57 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[Fix]=20#81=20-=20comment=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CourseUploadingRequestDto.swift | 2 +- .../Model/RunningModel/RunningModel.swift | 1 - .../Views/VC/CourseUploadVC.swift | 40 ++----------------- 3 files changed, 5 insertions(+), 38 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/RequestDto/CourseUploadingRequestDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/RequestDto/CourseUploadingRequestDto.swift index 17a8ca8c..186e94d3 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/RequestDto/CourseUploadingRequestDto.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/RequestDto/CourseUploadingRequestDto.swift @@ -10,6 +10,6 @@ import Foundation // MARK: - CourseUploadingRequestDto struct CourseUploadingRequestDto: Codable { - let courseID: Int + let courseId: Int let title, description: String } diff --git a/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift b/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift index e6cbb283..b9aa6ce0 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Model/RunningModel/RunningModel.swift @@ -19,7 +19,6 @@ struct RunningModel { var totalTime: Int? var region: String? var city: String? - var discription: String? /// HH:MM:SS 형식으로 반환 func getFormattedTotalTime() -> String? { diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift index efb0a92e..bb26a1d1 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseUploadVC.swift @@ -14,7 +14,7 @@ import Moya class CourseUploadVC: UIViewController { // MARK: - Properties - private var runningModel: RunningModel? +// private var runningModel: RunningModel? private let courseUploadingProvider = MoyaProvider( plugins: [NetworkLoggerPlugin(verbose: true)] ) @@ -130,31 +130,10 @@ extension CourseUploadVC { name: UIResponder.keyboardWillHideNotification, object: nil) } - - func setData(runningModel: RunningModel) { - self.runningModel = runningModel - self.mapImageView.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.mapImageView.setImage(with: imageUrl) - } - - private func pushToCourseDiscoveryVC() { - let nextVC = CourseDiscoveryVC() - self.navigationController?.pushViewController(nextVC, animated: true) - - } } // MARK: - @objc Function extension CourseUploadVC { - -// @objc private func pushToCourseDiscoveryVC() { -// let nextVC = CourseDiscoveryVC() -// self.navigationController?.pushViewController(nextVC, animated: true) -// } - @objc private func textFieldTextDidChange() { guard let text = courseTitleTextField.text else { return } @@ -341,12 +320,10 @@ extension CourseUploadVC: UITextViewDelegate { extension CourseUploadVC { private func uploadCourse() { - self.pushToCourseDiscoveryVC() - guard let runningModel = self.runningModel else { return } - guard let courseId = runningModel.courseId else { return } + guard let courseId = courseModel?.id else { return } guard let titletext = courseTitleTextField.text else { return } guard let descriptiontext = activityTextView.text else { return } - let requsetDto = CourseUploadingRequestDto(courseID: courseId, title: titletext, description: descriptiontext) + let requsetDto = CourseUploadingRequestDto(courseId: courseId, title: titletext, description: descriptiontext) LoadingIndicator.showLoading() courseUploadingProvider.request(.courseUploadingData(param: requsetDto)) { [weak self] response in @@ -356,16 +333,7 @@ extension CourseUploadVC { case .success(let result): let status = result.statusCode if 200..<300 ~= status { - do { - let responseDto = try result.map(BaseResponse.self) - if responseDto.status == 200 { - self.pushToCourseDiscoveryVC() - } else { - self.showToast(message: responseDto.message) - } - } catch { - print(error.localizedDescription) - } + self.navigationController?.popToRootViewController(animated: true) } if status >= 400 { print("400 error")