diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index 7f798265..0e26a227 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -136,6 +136,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 */; }; @@ -292,6 +294,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 = ""; }; @@ -744,6 +748,7 @@ children = ( DAD5A3E3296D526D00C8166B /* CourseDiscoveryRouter.swift */, DA97A02E296DC3300086760E /* CourseSearchingRouter.swift */, + DA97A034296E685C0086760E /* CourseUploadingRouter.swift */, ); path = CourseDiscoveryRouter; sourceTree = ""; @@ -1148,6 +1153,7 @@ DA97A029296DC2020086760E /* RequestDto */ = { isa = PBXGroup; children = ( + DA97A032296E65D80086760E /* CourseUploadingRequestDto.swift */, ); path = RequestDto; sourceTree = ""; @@ -1307,6 +1313,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 */, A3305A97296EF58C000B1A10 /* GoalRewardInfoDto.swift in Sources */, CE6655F4295D898400C64E12 /* UIViewController+.swift in Sources */, @@ -1416,6 +1423,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..186e94d3 --- /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/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 f918e429..bb26a1d1 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,15 @@ import UIKit import SnapKit import Then +import Moya 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 @@ -88,8 +92,8 @@ 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 위치 조정 @@ -127,19 +131,12 @@ extension CourseUploadVC { object: nil) } } - // 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 } - + if text.count > courseTitleMaxLength { let index = text.index(text.startIndex, offsetBy: courseTitleMaxLength) let newString = text[text.startIndex..= 400 { + print("400 error") + self.showNetworkFailureToast() + } + case .failure(let error): + print(error.localizedDescription) + self.showNetworkFailureToast() + } + } + } +}