Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
0AEBD608F3973389E8E1C6D6 /* Pods_Runnect_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 015778D02D5CDE0838284CD7 /* Pods_Runnect_iOS.framework */; };
232686362B03AF4400675A17 /* NetworkProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 232686352B03AF4400675A17 /* NetworkProvider.swift */; };
23EE06C12AC1AD5200CB3FF8 /* LocationSelectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE06C02AC1AD5200CB3FF8 /* LocationSelectView.swift */; };
23EE06C52AC1AE1900CB3FF8 /* BaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE06C42AC1AE1900CB3FF8 /* BaseView.swift */; };
23EE06C92AC1DED100CB3FF8 /* GesturePublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE06C82AC1DED100CB3FF8 /* GesturePublisher.swift */; };
Expand Down Expand Up @@ -177,6 +178,7 @@

/* Begin PBXFileReference section */
015778D02D5CDE0838284CD7 /* Pods_Runnect_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runnect_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
232686352B03AF4400675A17 /* NetworkProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProvider.swift; sourceTree = "<group>"; };
23EE06C02AC1AD5200CB3FF8 /* LocationSelectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSelectView.swift; sourceTree = "<group>"; };
23EE06C42AC1AE1900CB3FF8 /* BaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseView.swift; sourceTree = "<group>"; };
23EE06C82AC1DED100CB3FF8 /* GesturePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GesturePublisher.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1003,6 +1005,7 @@
CE6655BE295D82E200C64E12 /* .gitkeep */,
CE102C4929DBAD3D00E23E69 /* AuthInterceptor.swift */,
CEE59FD929DD6F7D00C791F1 /* Providers.swift */,
232686352B03AF4400675A17 /* NetworkProvider.swift */,
);
path = Service;
sourceTree = "<group>";
Expand Down Expand Up @@ -1534,6 +1537,7 @@
CE40BB2D296808B00030ABCA /* DepartureSearchingRouter.swift in Sources */,
CE15F5A4296C932E0023827C /* RunningModel.swift in Sources */,
CE17F02D2961BBA100E1DED0 /* ColorLiterals.swift in Sources */,
232686362B03AF4400675A17 /* NetworkProvider.swift in Sources */,
71BAD06C2B24D1F70061E31D /* UserProfileVC.swift in Sources */,
CEC2A68E2962AF2C00160BF7 /* RNMarker.swift in Sources */,
CE6655D2295D862A00C64E12 /* Publisher+Driver.swift in Sources */,
Expand Down
46 changes: 46 additions & 0 deletions Runnect-iOS/Runnect-iOS/Network/Service/NetworkProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// NetworkProvider.swift
// Runnect-iOS
//
// Created by Sojin Lee on 2023/11/14.
//

import Moya

enum ResponseResult<T> {
case success(T)
}

class NetworkProvider<Provider : TargetType> : MoyaProvider<Provider> {
func request<Model : Codable>(target : Provider, instance : Model.Type , vc: UIViewController, completion : @escaping(ResponseResult<Model>) -> ()){
self.request(target) { result in
switch result {
/// 서버 통신 성공
case .success(let response):
if (200..<300).contains(response.statusCode) {
if let decodeData = try? JSONDecoder().decode(instance, from: response.data) {
completion(.success(decodeData))
} else{
/// decoding error
vc.showNetworkFailureToast()
}
} else {
/// 응답 코드 400인 경우
vc.showNetworkFailureToast()
}
/// 서버 통신 실패
case .failure(let error):
if let response = error.response {
if let responseData = String(data: response.data, encoding: .utf8) {
print(responseData)
} else {
print(error.localizedDescription)
}
} else {
print(error.localizedDescription)
}
vc.showNetworkFailureToast()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ final class CourseDrawingVC: UIViewController {
private let courseProvider = Providers.courseProvider
private let departureSearchingProvider = Providers.departureSearchingProvider

private let networkProvider = NetworkProvider<DepartureSearchingRouter>(withAuth: false)

private var departureLocationModel: DepartureLocationModel?

var pathImage: UIImage?
Expand Down Expand Up @@ -194,7 +196,8 @@ extension CourseDrawingVC {

mapView.eventSubject.sink { [weak self] arr in
guard let self = self else { return }
self.searchLocationTmapAddress(latitude: arr[0], longitude: arr[1])
// self.searchLocationTmapAddress(latitude: arr[0], longitude: arr[1])
self.searchTest(latitude: arr[0], longitude: arr[1])
}.store(in: cancelBag)
}

Expand Down Expand Up @@ -496,4 +499,13 @@ extension CourseDrawingVC {
}
}
}

private func searchTest(latitude: Double, longitude: Double) {
networkProvider.request(target: .getLocationTmapAddress(latitude: latitude, longitude: longitude), instance: TmapAddressSearchingResponseDto.self, vc: self) { result in
switch result {
case .success(let data):
self.updateData(model: data.toDepartureLocationModel(latitude: latitude, longitude: longitude))
}
}
}
}
Comment on lines +503 to 511
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확실하게 짧아지긴 했네요,
꽤 꼼꼼하게 봤는데도, 고칠 부분은 찾지 못했습니다.
따로 NetworkProvider 클래스를 재사용하여 중복되는 코드들을 없애는 거는 초창기에 언급했던 거 같은데, 대부분 작업 끝나면 모두 바꿔봅시다~