Skip to content

Commit 0cd869d

Browse files
authored
Merge pull request #221 from Runnect/#214-코스그리기및업로드
[Feat] #214 - 코스그리기 및 업로드 팝업 추가
2 parents 17bd5f9 + 0ca4fd6 commit 0cd869d

File tree

10 files changed

+124
-98
lines changed

10 files changed

+124
-98
lines changed

Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomAlertVC.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class CustomAlertVC: UIViewController {
3737
}
3838
private let contentsLabel: UILabel = UILabel().then {
3939
$0.text = "코스를 만들었어요!\n지정한 코스는 보관함에서 볼 수 있어요."
40-
$0.font = .h5
40+
$0.font = .b4
4141
$0.textColor = .g2
4242
$0.textAlignment = .center
4343
$0.numberOfLines = 2
@@ -55,7 +55,6 @@ final class CustomAlertVC: UIViewController {
5555
}
5656

5757
// MARK: - View Life Cycle
58-
5958
override func viewDidLoad() {
6059
super.viewDidLoad()
6160
self.setUI()
@@ -119,6 +118,7 @@ extension CustomAlertVC {
119118

120119
private func setLayout() {
121120
view.addSubviews(alertView)
121+
122122
alertView.addSubviews(alertImageView, contentsLabel, buttonStackView)
123123

124124
alertView.snp.makeConstraints { make in
@@ -138,7 +138,6 @@ extension CustomAlertVC {
138138
make.leading.trailing.equalToSuperview().inset(10)
139139
make.centerX.equalToSuperview()
140140
}
141-
142141
buttonStackView.snp.makeConstraints { make in
143142
make.top.equalTo(contentsLabel.snp.bottom).offset(26)
144143
make.leading.trailing.equalToSuperview().inset(14)

Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ import UIKit
1010
import SnapKit
1111
import Then
1212

13+
enum AlertType {
14+
case defaultType
15+
case custom
16+
}
17+
1318
final class RNAlertVC: UIViewController {
1419

1520
// MARK: - Properties
16-
21+
var leftButtonTapAction: (()-> Void)?
1722
var rightButtonTapAction: (() -> Void)?
23+
var alertType: AlertType = .defaultType
1824

1925
// MARK: - UI Components
2026

@@ -69,8 +75,10 @@ final class RNAlertVC: UIViewController {
6975
extension RNAlertVC {
7076
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
7177
super.touchesBegan(touches, with: event)
72-
if let touch = touches.first, touch.view == self.view {
73-
dismiss(animated: false)
78+
if alertType == .defaultType {
79+
if let touch = touches.first, touch.view == self.view {
80+
dismiss(animated: false)
81+
}
7482
}
7583
}
7684

@@ -91,7 +99,8 @@ extension RNAlertVC {
9199

92100
extension RNAlertVC {
93101
@objc private func touchUpNoButton() {
94-
dismiss(animated: false)
102+
alertType == .defaultType
103+
? dismiss(animated: false) : self.leftButtonTapAction? ()
95104
}
96105

97106
@objc private func touchYesButton() {

Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/convertLocationObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension NMGLatLng {
2828
}
2929

3030
func toRNLocationModel() -> RNLocationModel {
31-
return RNLocationModel(lat: self.lat, long: self.lng)
31+
return RNLocationModel(latitude: self.lat, longitude: self.lng)
3232
}
3333
}
3434

Runnect-iOS/Runnect-iOS/Network/Dto/CourseDrawingDto/RequestDto/CourseDrawingRequestDto.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,19 @@ import Foundation
1111

1212
struct CourseDrawingRequestDto: Codable {
1313
let image: Data
14-
let data: CourseDrawingRequestData
14+
let path: [RNLocationModel]
15+
let title: String
16+
let distance: Float
17+
let departureAddress, departureName: String
1518
}
1619

20+
//"image" : 이미지 파일,
21+
// "path" : [{lat : 실수(double), long : 실수},{lat : 실수(double), long : 실수},{lat : 실수(double), long : 실수} ],
22+
// "title" : "한강 공원 한 바퀴",
23+
// "distance" : 4.4,
24+
// "departureAddress" : "전북 익산시 삼성동 100",
25+
// "departureName" : "보리의 집"
26+
1727
// MARK: - CourseDrawingRequestData
1828

1929
struct CourseDrawingRequestData: Codable {

Runnect-iOS/Runnect-iOS/Network/Dto/CourseDrawingDto/ResponseDto/CourseDrawingResponseData.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ import Foundation
1010
// MARK: - DataClass
1111

1212
struct CourseDrawingResponseData: Codable {
13-
let course: CourseDrawingResponse
14-
}
15-
16-
// MARK: - Course
17-
18-
struct CourseDrawingResponse: Codable {
1913
let id: Int
2014
let createdAt: String
2115
}

Runnect-iOS/Runnect-iOS/Network/Model/CourseDrawingModel/RNLocationModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
import Foundation
99

1010
struct RNLocationModel: Codable {
11-
let lat: Double
12-
let long: Double
11+
let latitude: Double
12+
let longitude: Double
1313
}

Runnect-iOS/Runnect-iOS/Network/Router/CourseRouter.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension CourseRouter: TargetType {
2929
var path: String {
3030
switch self {
3131
case .uploadCourseDrawing:
32-
return "/course"
32+
return "/course/v2"
3333
case .getAllPrivateCourse:
3434
return "/course/user"
3535
case .getPrivateCourseNotUploaded:
@@ -66,20 +66,22 @@ extension CourseRouter: TargetType {
6666
var content = [String: Any]()
6767

6868
var path = [[String: Any]]()
69+
var tempPath = String()
6970

7071
do {
71-
for location in param.data.path {
72+
for location in param.path {
7273
let locationData = try location.asParameter()
7374
path.append(locationData)
7475
}
75-
76+
7677
content["path"] = path
77-
content["distance"] = param.data.distance
78-
content["departureAddress"] = param.data.departureAddress
79-
content["departureName"] = param.data.departureName
78+
content["title"] = param.title
79+
content["distance"] = param.distance
80+
content["departureAddress"] = param.departureAddress
81+
content["departureName"] = param.departureName
8082

8183
let jsonData = try JSONSerialization.data(withJSONObject: content)
82-
let formData = MultipartFormData(provider: .data(jsonData), name: "data", mimeType: "application/json")
84+
let formData = MultipartFormData(provider: .data(jsonData), name: "courseCreateRequestDto", mimeType: "application/json")
8385
multipartFormData.append(formData)
8486
} catch {
8587
print(error.localizedDescription)

Runnect-iOS/Runnect-iOS/Network/Service/NetworkProvider.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@
77

88
import Moya
99

10-
enum ResponseResult<T> {
11-
case success(T)
12-
}
13-
1410
class NetworkProvider<Provider : TargetType> : MoyaProvider<Provider> {
15-
func request<Model : Codable>(target : Provider, instance : Model.Type , vc: UIViewController, completion : @escaping(ResponseResult<Model>) -> ()){
11+
func request<Model : Codable>(target : Provider, instance : Model.Type , vc: UIViewController, completion : @escaping(Model) -> ()){
1612
self.request(target) { result in
1713
switch result {
1814
/// 서버 통신 성공
1915
case .success(let response):
2016
if (200..<300).contains(response.statusCode) {
2117
if let decodeData = try? JSONDecoder().decode(instance, from: response.data) {
22-
completion(.success(decodeData))
18+
completion(decodeData)
2319
} else{
2420
/// decoding error
2521
vc.showNetworkFailureToast()

Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ import Moya
1313
final class CourseDrawingVC: UIViewController {
1414

1515
// MARK: - Properties
16-
17-
private let courseProvider = Providers.courseProvider
18-
private let departureSearchingProvider = Providers.departureSearchingProvider
19-
20-
private let networkProvider = NetworkProvider<DepartureSearchingRouter>(withAuth: false)
16+
private let departureSearchingProvider = NetworkProvider<DepartureSearchingRouter>(withAuth: false)
17+
private let courseProvider = NetworkProvider<CourseRouter>(withAuth: true)
2118

2219
private var departureLocationModel: DepartureLocationModel?
2320

@@ -196,8 +193,8 @@ extension CourseDrawingVC {
196193

197194
mapView.eventSubject.sink { [weak self] arr in
198195
guard let self = self else { return }
199-
// self.searchLocationTmapAddress(latitude: arr[0], longitude: arr[1])
200-
self.searchTest(latitude: arr[0], longitude: arr[1])
196+
self.searchLocationTmapAddress(latitude: arr[0], longitude: arr[1])
197+
// self.searchTest(latitude: arr[0], longitude: arr[1])
201198
}.store(in: cancelBag)
202199
}
203200

@@ -434,13 +431,14 @@ extension CourseDrawingVC {
434431
guard let imageData = image.jpegData(compressionQuality: 1.0) else { return nil }
435432
guard let departureLocationModel = self.departureLocationModel else { return nil }
436433
let path = mapView.getMarkersLatLng().map { $0.toRNLocationModel() }
437-
let courseDrawingRequestData = CourseDrawingRequestData(path: path,
438-
// title : self.courseName,
439-
distance: self.distance,
440-
departureAddress: departureLocationModel.departureAddress,
441-
departureName: departureLocationModel.departureName)
442434

443-
let courseDrawingRequestDto = CourseDrawingRequestDto(image: imageData, data: courseDrawingRequestData)
435+
let courseDrawingRequestDto = CourseDrawingRequestDto(
436+
image: imageData,
437+
path: path,
438+
title: self.courseName,
439+
distance: self.distance,
440+
departureAddress: departureLocationModel.departureAddress,
441+
departureName: departureLocationModel.departureName)
444442

445443
return courseDrawingRequestDto
446444
}
@@ -449,63 +447,16 @@ extension CourseDrawingVC {
449447
guard let requestDto = makecourseDrawingRequestDto() else { return }
450448
LoadingIndicator.showLoading()
451449

452-
courseProvider.request(.uploadCourseDrawing(param: requestDto)) {[weak self] response in
453-
guard let self = self else { return }
450+
courseProvider.request(target: .uploadCourseDrawing(param: requestDto), instance: BaseResponse<CourseDrawingResponseData>.self, vc: self) { response in
454451
LoadingIndicator.hideLoading()
455-
switch response {
456-
case .success(let result):
457-
let status = result.statusCode
458-
if 200..<300 ~= status {
459-
do {
460-
let responseDto = try result.map(BaseResponse<CourseDrawingResponseData>.self)
461-
guard let data = responseDto.data else { return }
462-
self.presentAlertVC(courseId: data.course.id)
463-
} catch {
464-
print(error.localizedDescription)
465-
}
466-
}
467-
if status >= 400 {
468-
print("400 error")
469-
self.showNetworkFailureToast()
470-
}
471-
case .failure(let error):
472-
print(error.localizedDescription)
473-
self.showNetworkFailureToast()
474-
}
452+
guard let data = response.data else { return }
453+
self.presentAlertVC(courseId: data.id)
475454
}
476455
}
477456

478457
private func searchLocationTmapAddress(latitude: Double, longitude: Double) {
479-
departureSearchingProvider
480-
.request(.getLocationTmapAddress(latitude: latitude, longitude: longitude)) { [weak self] response in
481-
guard let self = self else { return }
482-
switch response {
483-
case .success(let result):
484-
let status = result.statusCode
485-
if 200..<300 ~= status {
486-
do {
487-
let responseDto = try result.map(TmapAddressSearchingResponseDto.self)
488-
self.updateData(model: responseDto.toDepartureLocationModel(latitude: latitude, longitude: longitude))
489-
} catch {
490-
print(error.localizedDescription)
491-
}
492-
}
493-
if status >= 400 {
494-
print("400 error")
495-
}
496-
case .failure(let error):
497-
print(error.localizedDescription)
498-
self.showToast(message: "네트워크 통신 실패")
499-
}
500-
}
501-
}
502-
503-
private func searchTest(latitude: Double, longitude: Double) {
504-
networkProvider.request(target: .getLocationTmapAddress(latitude: latitude, longitude: longitude), instance: TmapAddressSearchingResponseDto.self, vc: self) { result in
505-
switch result {
506-
case .success(let data):
458+
departureSearchingProvider.request(target: .getLocationTmapAddress(latitude: latitude, longitude: longitude), instance: TmapAddressSearchingResponseDto.self, vc: self) { data in
507459
self.updateData(model: data.toDepartureLocationModel(latitude: latitude, longitude: longitude))
508-
}
509460
}
510461
}
511462
}

0 commit comments

Comments
 (0)