Skip to content

Commit

Permalink
[Refactor] Runnect#112 - createAndDeleteScrap API를 ScrapRouter로 위치 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwogus0128 committed Feb 19, 2023
1 parent a92a9ff commit 38440f9
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Moya

enum UploadedCourseDetailRouter {
case getUploadedCourseDetail(publicCourseId: Int)
case createAndDeleteScrap(publicCourseId: Int, scrapTF: Bool)
}

extension UploadedCourseDetailRouter: TargetType {
Expand All @@ -27,32 +26,26 @@ extension UploadedCourseDetailRouter: TargetType {
switch self {
case .getUploadedCourseDetail(let publicCourseId):
return "/public-course/detail/\(publicCourseId)"
case .createAndDeleteScrap:
return "/scrap"
}
}

var method: Moya.Method {
switch self {
case .getUploadedCourseDetail:
return .get
case .createAndDeleteScrap:
return .post
}
}

var task: Moya.Task {
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
}
}
Expand Down
44 changes: 44 additions & 0 deletions Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ final class CourseDetailVC: UIViewController {

// MARK: - Properties

private let scrapProvider = MoyaProvider<ScrapRouter>(
plugins: [NetworkLoggerPlugin(verbose: true)]
)

private let courseDetailProvider = MoyaProvider<UploadedCourseDetailRouter>(
plugins: [NetworkLoggerPlugin(verbose: true)]
)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class CourseDiscoveryVC: UIViewController {
plugins: [NetworkLoggerPlugin(verbose: true)]
)

private let courseDetailProvider = MoyaProvider<UploadedCourseDetailRouter>(
private let scrapProvider = MoyaProvider<ScrapRouter>(
plugins: [NetworkLoggerPlugin(verbose: true)]
)

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class CourseSearchVC: UIViewController {
plugins: [NetworkLoggerPlugin(verbose: true)]
)

private let courseDetailProvider = MoyaProvider<UploadedCourseDetailRouter>(
private let scrapProvider = MoyaProvider<ScrapRouter>(
plugins: [NetworkLoggerPlugin(verbose: true)]
)

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class CourseStorageVC: UIViewController {
plugins: [NetworkLoggerPlugin(verbose: true)]
)

private let courseDetailProvider = MoyaProvider<UploadedCourseDetailRouter>(
private let scrapProvider = MoyaProvider<ScrapRouter>(
plugins: [NetworkLoggerPlugin(verbose: true)]
)

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 38440f9

Please sign in to comment.