From 38440f98f47192121b18c5c569e646f2d0eb708e Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Mon, 20 Feb 2023 00:01:30 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]=20#112=20-=20createAndDeleteScrap=20?= =?UTF-8?q?API=EB=A5=BC=20ScrapRouter=EB=A1=9C=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UploadedCourseDetailRouter.swift | 9 +--- .../Network/Router/ScrapRouter.swift | 44 +++++++++++++++++++ .../CourseDetail/VC/CourseDetailVC.swift | 6 ++- .../Views/VC/CourseDiscoveryVC.swift | 4 +- .../Views/VC/CourseSearchVC.swift | 4 +- .../CourseStorage/VC/CourseStorageVC.swift | 4 +- 6 files changed, 56 insertions(+), 15 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/CourseDetailRouter/UploadedCourseDetailRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/CourseDetailRouter/UploadedCourseDetailRouter.swift index 2e0446e5..caf87e03 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/CourseDetailRouter/UploadedCourseDetailRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/CourseDetailRouter/UploadedCourseDetailRouter.swift @@ -11,7 +11,6 @@ import Moya enum UploadedCourseDetailRouter { case getUploadedCourseDetail(publicCourseId: Int) - case createAndDeleteScrap(publicCourseId: Int, scrapTF: Bool) } extension UploadedCourseDetailRouter: TargetType { @@ -27,8 +26,6 @@ extension UploadedCourseDetailRouter: TargetType { switch self { case .getUploadedCourseDetail(let publicCourseId): return "/public-course/detail/\(publicCourseId)" - case .createAndDeleteScrap: - return "/scrap" } } @@ -36,8 +33,6 @@ extension UploadedCourseDetailRouter: TargetType { switch self { case .getUploadedCourseDetail: return .get - case .createAndDeleteScrap: - return .post } } @@ -45,14 +40,12 @@ extension UploadedCourseDetailRouter: TargetType { switch self { case .getUploadedCourseDetail: return .requestPlain - case .createAndDeleteScrap(let publicCourseId, let scrapTF): - return .requestParameters(parameters: ["publicCourseId": publicCourseId, "scrapTF": scrapTF], encoding: JSONEncoding.default) } } var headers: [String: String]? { switch self { - case .getUploadedCourseDetail, .createAndDeleteScrap: + case .getUploadedCourseDetail: return Config.headerWithDeviceId } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift index 89dfa2a8..3c5eec55 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift @@ -6,3 +6,47 @@ // import Foundation + +import Moya + +enum ScrapRouter { + case createAndDeleteScrap(publicCourseId: Int, scrapTF: Bool) +} + +extension ScrapRouter: 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 .createAndDeleteScrap: + return "/scrap" + } + } + + var method: Moya.Method { + switch self { + case .createAndDeleteScrap: + return .post + } + } + + var task: Moya.Task { + switch self { + case .createAndDeleteScrap(let publicCourseId, let scrapTF): + return .requestParameters(parameters: ["publicCourseId": publicCourseId, "scrapTF": scrapTF], encoding: JSONEncoding.default) + } + } + + var headers: [String: String]? { + switch self { + case .createAndDeleteScrap: + return Config.headerWithDeviceId + } + } +} diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDetail/VC/CourseDetailVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDetail/VC/CourseDetailVC.swift index bfda381e..cc84fdce 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDetail/VC/CourseDetailVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDetail/VC/CourseDetailVC.swift @@ -16,6 +16,10 @@ final class CourseDetailVC: UIViewController { // MARK: - Properties + private let scrapProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) + private let courseDetailProvider = MoyaProvider( plugins: [NetworkLoggerPlugin(verbose: true)] ) @@ -353,7 +357,7 @@ extension CourseDetailVC { private func scrapCourse(scrapTF: Bool) { guard let publicCourseId = self.publicCourseId else { return } LoadingIndicator.showLoading() - courseDetailProvider.request(.createAndDeleteScrap(publicCourseId: publicCourseId, scrapTF: scrapTF)) { [weak self] response in + scrapProvider.request(.createAndDeleteScrap(publicCourseId: publicCourseId, scrapTF: scrapTF)) { [weak self] response in LoadingIndicator.hideLoading() guard let self = self else { return } switch response { diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseDiscoveryVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseDiscoveryVC.swift index 73336bad..b2f1a2ee 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseDiscoveryVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseDiscoveryVC.swift @@ -19,7 +19,7 @@ final class CourseDiscoveryVC: UIViewController { plugins: [NetworkLoggerPlugin(verbose: true)] ) - private let courseDetailProvider = MoyaProvider( + private let scrapProvider = MoyaProvider( plugins: [NetworkLoggerPlugin(verbose: true)] ) @@ -276,7 +276,7 @@ extension CourseDiscoveryVC { private func scrapCourse(publicCourseId: Int, scrapTF: Bool) { LoadingIndicator.showLoading() - courseDetailProvider.request(.createAndDeleteScrap(publicCourseId: publicCourseId, scrapTF: scrapTF)) { [weak self] response in + scrapProvider.request(.createAndDeleteScrap(publicCourseId: publicCourseId, scrapTF: scrapTF)) { [weak self] response in LoadingIndicator.hideLoading() guard let self = self else { return } switch response { 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 e8aeea67..d7a8cf81 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseSearchVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseSearchVC.swift @@ -19,7 +19,7 @@ final class CourseSearchVC: UIViewController { plugins: [NetworkLoggerPlugin(verbose: true)] ) - private let courseDetailProvider = MoyaProvider( + private let scrapProvider = MoyaProvider( plugins: [NetworkLoggerPlugin(verbose: true)] ) @@ -246,7 +246,7 @@ extension CourseSearchVC { private func scrapCourse(publicCourseId: Int, scrapTF: Bool) { LoadingIndicator.showLoading() - courseDetailProvider.request(.createAndDeleteScrap(publicCourseId: publicCourseId, scrapTF: scrapTF)) { [weak self] response in + scrapProvider.request(.createAndDeleteScrap(publicCourseId: publicCourseId, scrapTF: scrapTF)) { [weak self] response in LoadingIndicator.hideLoading() guard let self = self else { return } switch response { diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/VC/CourseStorageVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/VC/CourseStorageVC.swift index e7d70dde..040d8a4a 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/VC/CourseStorageVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/VC/CourseStorageVC.swift @@ -18,7 +18,7 @@ final class CourseStorageVC: UIViewController { plugins: [NetworkLoggerPlugin(verbose: true)] ) - private let courseDetailProvider = MoyaProvider( + private let scrapProvider = MoyaProvider( plugins: [NetworkLoggerPlugin(verbose: true)] ) @@ -198,7 +198,7 @@ extension CourseStorageVC { private func scrapCourse(publicCourseId: Int, scrapTF: Bool) { LoadingIndicator.showLoading() - courseDetailProvider.request(.createAndDeleteScrap(publicCourseId: publicCourseId, scrapTF: scrapTF)) { [weak self] response in + scrapProvider.request(.createAndDeleteScrap(publicCourseId: publicCourseId, scrapTF: scrapTF)) { [weak self] response in LoadingIndicator.hideLoading() guard let self = self else { return } switch response {