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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class CustomAlertVC: UIViewController {
}
private let contentsLabel: UILabel = UILabel().then {
$0.text = "코스를 만들었어요!\n지정한 코스는 보관함에서 볼 수 있어요."
$0.font = .h5
$0.font = .b4
$0.textColor = .g2
$0.textAlignment = .center
$0.numberOfLines = 2
Expand All @@ -55,7 +55,6 @@ final class CustomAlertVC: UIViewController {
}

// MARK: - View Life Cycle

override func viewDidLoad() {
super.viewDidLoad()
self.setUI()
Expand Down Expand Up @@ -119,6 +118,7 @@ extension CustomAlertVC {

private func setLayout() {
view.addSubviews(alertView)

alertView.addSubviews(alertImageView, contentsLabel, buttonStackView)

alertView.snp.makeConstraints { make in
Expand All @@ -138,7 +138,6 @@ extension CustomAlertVC {
make.leading.trailing.equalToSuperview().inset(10)
make.centerX.equalToSuperview()
}

buttonStackView.snp.makeConstraints { make in
make.top.equalTo(contentsLabel.snp.bottom).offset(26)
make.leading.trailing.equalToSuperview().inset(14)
Expand Down
17 changes: 13 additions & 4 deletions Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ import UIKit
import SnapKit
import Then

enum AlertType {
case defaultType
case custom
}

Comment on lines +13 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

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

OCP 원칙 잘 지킨거 좋네요

final class RNAlertVC: UIViewController {

// MARK: - Properties

var leftButtonTapAction: (()-> Void)?
var rightButtonTapAction: (() -> Void)?
var alertType: AlertType = .defaultType

// MARK: - UI Components

Expand Down Expand Up @@ -69,8 +75,10 @@ final class RNAlertVC: UIViewController {
extension RNAlertVC {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
if let touch = touches.first, touch.view == self.view {
dismiss(animated: false)
if alertType == .defaultType {
if let touch = touches.first, touch.view == self.view {
dismiss(animated: false)
}
}
}

Expand All @@ -91,7 +99,8 @@ extension RNAlertVC {

extension RNAlertVC {
@objc private func touchUpNoButton() {
dismiss(animated: false)
alertType == .defaultType
? dismiss(animated: false) : self.leftButtonTapAction? ()
}

@objc private func touchYesButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension NMGLatLng {
}

func toRNLocationModel() -> RNLocationModel {
return RNLocationModel(lat: self.lat, long: self.lng)
return RNLocationModel(latitude: self.lat, longitude: self.lng)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ import Foundation

struct CourseDrawingRequestDto: Codable {
let image: Data
let data: CourseDrawingRequestData
let path: [RNLocationModel]
let title: String
let distance: Float
let departureAddress, departureName: String
}

//"image" : 이미지 파일,
// "path" : [{lat : 실수(double), long : 실수},{lat : 실수(double), long : 실수},{lat : 실수(double), long : 실수} ],
// "title" : "한강 공원 한 바퀴",
// "distance" : 4.4,
// "departureAddress" : "전북 익산시 삼성동 100",
// "departureName" : "보리의 집"

// MARK: - CourseDrawingRequestData

struct CourseDrawingRequestData: Codable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import Foundation
// MARK: - DataClass

struct CourseDrawingResponseData: Codable {
let course: CourseDrawingResponse
}

// MARK: - Course

struct CourseDrawingResponse: Codable {
let id: Int
let createdAt: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
import Foundation

struct RNLocationModel: Codable {
let lat: Double
let long: Double
let latitude: Double
let longitude: Double
Comment on lines +11 to +12
Copy link
Collaborator Author

@513sojin 513sojin Dec 11, 2023

Choose a reason for hiding this comment

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

< 코스 생성 api 관련 바뀐 부분> @thingineeer

  1. RNLocationModel lat, long명 바뀜
  2. path 바뀜
  3. 보내줄때 name이 바뀜
    let formData = MultipartFormData(provider: .data(jsonData), name: "courseCreateRequestDto", mimeType: "application/json")

마지막 커밋 확인 부탁드립니다 !!

}
16 changes: 9 additions & 7 deletions Runnect-iOS/Runnect-iOS/Network/Router/CourseRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension CourseRouter: TargetType {
var path: String {
switch self {
case .uploadCourseDrawing:
return "/course"
return "/course/v2"
case .getAllPrivateCourse:
return "/course/user"
case .getPrivateCourseNotUploaded:
Expand Down Expand Up @@ -66,20 +66,22 @@ extension CourseRouter: TargetType {
var content = [String: Any]()

var path = [[String: Any]]()
var tempPath = String()

do {
for location in param.data.path {
for location in param.path {
let locationData = try location.asParameter()
path.append(locationData)
}

content["path"] = path
content["distance"] = param.data.distance
content["departureAddress"] = param.data.departureAddress
content["departureName"] = param.data.departureName
content["title"] = param.title
content["distance"] = param.distance
content["departureAddress"] = param.departureAddress
content["departureName"] = param.departureName

let jsonData = try JSONSerialization.data(withJSONObject: content)
let formData = MultipartFormData(provider: .data(jsonData), name: "data", mimeType: "application/json")
let formData = MultipartFormData(provider: .data(jsonData), name: "courseCreateRequestDto", mimeType: "application/json")
Copy link
Collaborator

Choose a reason for hiding this comment

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

name: "courseCreateRequestDto" 이 부분이 의미하는바가 뭔지 알 수 있을까요??

Copy link
Collaborator Author

@513sojin 513sojin Dec 13, 2023

Choose a reason for hiding this comment

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

스크린샷 2023-12-11 오후 6 50 20
수정된 api에서는 courseCreateRequestDto에 현재의 path나 주소값 등등을 넣어서 보내주고 있습니다 !!

multipartFormData.append(formData)
} catch {
print(error.localizedDescription)
Expand Down
8 changes: 2 additions & 6 deletions Runnect-iOS/Runnect-iOS/Network/Service/NetworkProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@

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>) -> ()){
func request<Model : Codable>(target : Provider, instance : Model.Type , vc: UIViewController, completion : @escaping(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))
completion(decodeData)
} else{
/// decoding error
vc.showNetworkFailureToast()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ import Moya
final class CourseDrawingVC: UIViewController {

// MARK: - Properties

private let courseProvider = Providers.courseProvider
private let departureSearchingProvider = Providers.departureSearchingProvider

private let networkProvider = NetworkProvider<DepartureSearchingRouter>(withAuth: false)
private let departureSearchingProvider = NetworkProvider<DepartureSearchingRouter>(withAuth: false)
private let courseProvider = NetworkProvider<CourseRouter>(withAuth: true)

private var departureLocationModel: DepartureLocationModel?

Expand Down Expand Up @@ -196,8 +193,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.searchTest(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 @@ -434,13 +431,14 @@ extension CourseDrawingVC {
guard let imageData = image.jpegData(compressionQuality: 1.0) else { return nil }
guard let departureLocationModel = self.departureLocationModel else { return nil }
let path = mapView.getMarkersLatLng().map { $0.toRNLocationModel() }
let courseDrawingRequestData = CourseDrawingRequestData(path: path,
// title : self.courseName,
distance: self.distance,
departureAddress: departureLocationModel.departureAddress,
departureName: departureLocationModel.departureName)

let courseDrawingRequestDto = CourseDrawingRequestDto(image: imageData, data: courseDrawingRequestData)
let courseDrawingRequestDto = CourseDrawingRequestDto(
image: imageData,
path: path,
title: self.courseName,
distance: self.distance,
departureAddress: departureLocationModel.departureAddress,
departureName: departureLocationModel.departureName)

return courseDrawingRequestDto
}
Expand All @@ -449,63 +447,16 @@ extension CourseDrawingVC {
guard let requestDto = makecourseDrawingRequestDto() else { return }
LoadingIndicator.showLoading()

courseProvider.request(.uploadCourseDrawing(param: requestDto)) {[weak self] response in
guard let self = self else { return }
courseProvider.request(target: .uploadCourseDrawing(param: requestDto), instance: BaseResponse<CourseDrawingResponseData>.self, vc: self) { response in
LoadingIndicator.hideLoading()
switch response {
case .success(let result):
let status = result.statusCode
if 200..<300 ~= status {
do {
let responseDto = try result.map(BaseResponse<CourseDrawingResponseData>.self)
guard let data = responseDto.data else { return }
self.presentAlertVC(courseId: data.course.id)
} catch {
print(error.localizedDescription)
}
}
if status >= 400 {
print("400 error")
self.showNetworkFailureToast()
}
case .failure(let error):
print(error.localizedDescription)
self.showNetworkFailureToast()
}
guard let data = response.data else { return }
self.presentAlertVC(courseId: data.id)
}
}

private func searchLocationTmapAddress(latitude: Double, longitude: Double) {
departureSearchingProvider
.request(.getLocationTmapAddress(latitude: latitude, longitude: longitude)) { [weak self] response in
guard let self = self else { return }
switch response {
case .success(let result):
let status = result.statusCode
if 200..<300 ~= status {
do {
let responseDto = try result.map(TmapAddressSearchingResponseDto.self)
self.updateData(model: responseDto.toDepartureLocationModel(latitude: latitude, longitude: longitude))
} catch {
print(error.localizedDescription)
}
}
if status >= 400 {
print("400 error")
}
case .failure(let error):
print(error.localizedDescription)
self.showToast(message: "네트워크 통신 실패")
}
}
}

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):
departureSearchingProvider.request(target: .getLocationTmapAddress(latitude: latitude, longitude: longitude), instance: TmapAddressSearchingResponseDto.self, vc: self) { data in
self.updateData(model: data.toDepartureLocationModel(latitude: latitude, longitude: longitude))
}
}
}
}
Loading