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
16 changes: 16 additions & 0 deletions Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
CEEC6B4B2961D89700D00E1E /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */; };
CEF3CD9A296DB305002723A1 /* CourseDetailResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */; };
CEFA9A2F29FC263700F2D0CF /* UserDeleteResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFA9A2E29FC263700F2D0CF /* UserDeleteResponseDto.swift */; };
DA0587F22A05D54100B72869 /* EditCourseRequestDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0587F12A05D54100B72869 /* EditCourseRequestDto.swift */; };
DA0587F42A05DEC000B72869 /* CourseEditVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0587F32A05DEC000B72869 /* CourseEditVC.swift */; };
DA20D847296697A600F1581F /* MyCourseSelectVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D846296697A600F1581F /* MyCourseSelectVC.swift */; };
DA20D849296697B400F1581F /* CourseUploadVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D848296697B400F1581F /* CourseUploadVC.swift */; };
DA20D84E2966A9B300F1581F /* CourseSearchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */; };
Expand Down Expand Up @@ -307,6 +309,8 @@
CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = "<group>"; };
CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailResponseDto.swift; sourceTree = "<group>"; };
CEFA9A2E29FC263700F2D0CF /* UserDeleteResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDeleteResponseDto.swift; sourceTree = "<group>"; };
DA0587F12A05D54100B72869 /* EditCourseRequestDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditCourseRequestDto.swift; sourceTree = "<group>"; };
DA0587F32A05DEC000B72869 /* CourseEditVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseEditVC.swift; sourceTree = "<group>"; };
DA20D846296697A600F1581F /* MyCourseSelectVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyCourseSelectVC.swift; sourceTree = "<group>"; };
DA20D848296697B400F1581F /* CourseUploadVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseUploadVC.swift; sourceTree = "<group>"; };
DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseSearchVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -441,6 +445,7 @@
CE10063329680BFD00FD31FB /* CourseDetailDto */ = {
isa = PBXGroup;
children = (
DA0587F02A05D52100B72869 /* RequestDto */,
CE4942AB296FCD1000736701 /* ResponseDto */,
);
path = CourseDetailDto;
Expand Down Expand Up @@ -719,6 +724,7 @@
isa = PBXGroup;
children = (
A3BC2F422966A93100198261 /* CourseDetailVC.swift */,
DA0587F32A05DEC000B72869 /* CourseEditVC.swift */,
);
path = VC;
sourceTree = "<group>";
Expand Down Expand Up @@ -1144,6 +1150,14 @@
path = VC;
sourceTree = "<group>";
};
DA0587F02A05D52100B72869 /* RequestDto */ = {
isa = PBXGroup;
children = (
DA0587F12A05D54100B72869 /* EditCourseRequestDto.swift */,
);
path = RequestDto;
sourceTree = "<group>";
};
DA97A029296DC2020086760E /* RequestDto */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1365,6 +1379,7 @@
A3F67AE2296D33AC001598A2 /* MyPageDto.swift in Sources */,
CE591EA1296D5EB5000FCBB3 /* PrivateCourseResponseDto.swift in Sources */,
A3BC2F3F2964706100198261 /* UploadedCourseInfoCVC.swift in Sources */,
DA0587F42A05DEC000B72869 /* CourseEditVC.swift in Sources */,
CE6655FE295D912300C64E12 /* calculateTopInset.swift in Sources */,
CEEC6B492961C5E200D00E1E /* SplashVC.swift in Sources */,
CE6655D0295D85FF00C64E12 /* CancelBag.swift in Sources */,
Expand Down Expand Up @@ -1423,6 +1438,7 @@
CE17F02D2961BBA100E1DED0 /* ColorLiterals.swift in Sources */,
CEC2A68E2962AF2C00160BF7 /* RNMarker.swift in Sources */,
CE6655D2295D862A00C64E12 /* Publisher+Driver.swift in Sources */,
DA0587F22A05D54100B72869 /* EditCourseRequestDto.swift in Sources */,
A3C2CACE29E313CC00EC525B /* SettingVC.swift in Sources */,
CE21C02E299E601700F62AF5 /* StampRouter.swift in Sources */,
CE6655E6295D887F00C64E12 /* UIStackView+.swift in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions Runnect-iOS/Runnect-iOS/Global/Literal/ImageLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ enum ImageLiterals {
static var icLogoCircle: UIImage { .load(named: "ic_logo_circle") }
static var icMore: UIImage { .load(named: "ic_more") }
static var icPlus: UIImage { .load(named: "ic_plus") }
static var icFrameEdit: UIImage {
.load(named: "ic_frame_edit")
}

// img
static var imgBackground: UIImage { .load(named: "img_background") }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Frame 2064.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Frame 2064@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Frame 2064@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ final class RNAlertVC: UIViewController {
private let descriptionLabel = UILabel().then {
$0.font = .b4
$0.textColor = .g2
$0.numberOfLines = 0
$0.textAlignment = .center
}

private lazy var yesButton = UIButton(type: .custom).then {
Expand Down Expand Up @@ -105,7 +107,7 @@ extension RNAlertVC {
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
make.leading.trailing.equalToSuperview().inset(30)
make.height.equalTo(126)
// make.height.equalTo(126)
}

containerView.addSubviews(descriptionLabel, yesButton, noButton)
Expand All @@ -116,6 +118,7 @@ extension RNAlertVC {
}

noButton.snp.makeConstraints { make in
make.top.equalTo(descriptionLabel.snp.bottom).offset(20)
make.leading.equalToSuperview().offset(16)
make.trailing.equalTo(containerView.snp.centerX).offset(-4)
make.height.equalTo(44)
Expand All @@ -124,6 +127,7 @@ extension RNAlertVC {
}

yesButton.snp.makeConstraints { make in
make.top.equalTo(noButton.snp.top)
make.trailing.equalToSuperview().inset(16)
make.leading.equalTo(containerView.snp.centerX).offset(4)
make.height.equalTo(44)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// EditCourseReguestDto.swift
// Runnect-iOS
//
// Created by YEONOO on 2023/05/06.
//

import Foundation

// MARK: - EditCourseReguestDto

struct EditCourseRequestDto: Codable {
let title, description: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ struct UploadUser: Codable {
let nickname: String
let level: Int
let image: String
let isNowUser: Bool?
}
7 changes: 7 additions & 0 deletions Runnect-iOS/Runnect-iOS/Network/Router/CourseRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum CourseRouter {
case getAllPrivateCourse
case getPrivateCourseNotUploaded
case getCourseDetail(courseId: Int)
case deleteCourse(courseIdList: [Int])
}

extension CourseRouter: TargetType {
Expand All @@ -35,6 +36,8 @@ extension CourseRouter: TargetType {
return "/course/private/user"
case .getCourseDetail(let courseId):
return "/course/detail/\(courseId)"
case .deleteCourse:
return "/course"
}
}

Expand All @@ -44,6 +47,8 @@ extension CourseRouter: TargetType {
return .post
case .getAllPrivateCourse, .getPrivateCourseNotUploaded, .getCourseDetail:
return .get
case .deleteCourse:
return .put
}
}

Expand Down Expand Up @@ -81,6 +86,8 @@ extension CourseRouter: TargetType {
}

return .uploadMultipart(multipartFormData)
case .deleteCourse(let courseIdList):
return .requestParameters(parameters: ["courseIdList": courseIdList], encoding: JSONEncoding.default)
case .getAllPrivateCourse, .getPrivateCourseNotUploaded, .getCourseDetail:
return .requestPlain
}
Expand Down
12 changes: 11 additions & 1 deletion Runnect-iOS/Runnect-iOS/Network/Router/PublicCourseRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ enum PublicCourseRouter {
case courseUploadingData(param: CourseUploadingRequestDto)
case getUploadedCourseDetail(publicCourseId: Int)
case getUploadedCourseInfo
}
case updatePublicCourse(publicCourseId: Int, editCourseRequestDto: EditCourseRequestDto)
}

extension PublicCourseRouter: TargetType {

Expand All @@ -35,6 +36,8 @@ extension PublicCourseRouter: TargetType {
return "/public-course/detail/\(publicCourseId)"
case .getUploadedCourseInfo:
return "/public-course/user"
case .updatePublicCourse(let publicCourseId, _):
return "/public-course/\(publicCourseId)"
}
}

Expand All @@ -44,6 +47,8 @@ extension PublicCourseRouter: TargetType {
return .get
case .courseUploadingData:
return .post
case .updatePublicCourse:
return .patch
}
}

Expand All @@ -56,6 +61,11 @@ extension PublicCourseRouter: TargetType {
return .requestParameters(parameters: try param.asParameter(), encoding: JSONEncoding.default)
} catch {
fatalError("Encoding 실패")}
case .updatePublicCourse(_, let param):
do {
return .requestParameters(parameters: try param.asParameter(), encoding: JSONEncoding.default)
} catch {
fatalError("Encoding 실패")}
case .getCourseData, .getUploadedCourseDetail, .getUploadedCourseInfo:
return .requestPlain
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SnapKit
import Then
import NMapsMap
import Moya
import SafariServices

final class CourseDetailVC: UIViewController {

Expand All @@ -24,8 +25,11 @@ final class CourseDetailVC: UIViewController {

private var courseModel: Course?

private var uploadedCourseDetailModel: UploadedCourseDetailResponseDto?

private var courseId: Int?
private var publicCourseId: Int?
private var isMyCourse: Bool?

// MARK: - UI Components
private lazy var navibar = CustomNavigationBar(self, type: .titleWithLeftButton)
Expand Down Expand Up @@ -78,7 +82,7 @@ final class CourseDetailVC: UIViewController {
$0.textColor = .g1
$0.font = .h4
}

private let courseDistanceInfoView = CourseDetailInfoView(title: "거리", description: "0.0km")

private let courseDepartureInfoView = CourseDetailInfoView(title: "출발지", description: "위치")
Expand All @@ -100,9 +104,8 @@ final class CourseDetailVC: UIViewController {
$0.isScrollEnabled = false
$0.sizeToFit()
}

// MARK: - View Life Cycle

override func viewDidLoad() {
super.viewDidLoad()
setNavigationBar()
Expand All @@ -126,30 +129,50 @@ extension CourseDetailVC {
}

@objc func moreButtonDidTap() {

let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

let saveAction = UIAlertAction(title: "저장하기", style: .default, handler: nil)
let reportAction = UIAlertAction(title: "신고하기", style: .destructive, handler: {(_: UIAlertAction!) in
//report action
})
let cancelAction = UIAlertAction(title: "닫기", style: .cancel, handler: nil)

[ saveAction, reportAction, cancelAction ].forEach { alertController.addAction($0) }

present(alertController, animated: true, completion: nil)

}
guard let isMyCourse = self.isMyCourse, let uploadedCourseDetailModel = self.uploadedCourseDetailModel else { return }

let cancelAction = UIAlertAction(title: "닫기", style: .cancel, handler: nil)

if isMyCourse == true {
let editAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let courseEditVC = CourseEditVC()
courseEditVC.loadData(model: uploadedCourseDetailModel)
courseEditVC.publicCourseId = self.publicCourseId
let editAction = UIAlertAction(title: "수정하기", style: .default, handler: {(_: UIAlertAction!) in
self.navigationController?.pushViewController(courseEditVC, animated: false)
})
let deleteVC = RNAlertVC(description: "코스를 정말로 삭제하시겠어요?")
deleteVC.rightButtonTapAction = { [weak self] in
deleteVC.dismiss(animated: false)
self?.deleteCourse()
}
deleteVC.modalPresentationStyle = .overFullScreen
let deleteAction = UIAlertAction(title: "삭제하기", style: .destructive, handler: {(_: UIAlertAction!) in
self.present(deleteVC, animated: false, completion: nil)})
[ editAction, deleteAction, cancelAction].forEach { editAlertController.addAction($0) }
present(editAlertController, animated: false, completion: nil)
} else {
// 신고폼 올라오는 거(유저아이디가 내가 아닌 경우)
let reportAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let formUrl = NSURL(string: "https://docs.google.com/forms/d/e/1FAIpQLSek2rkClKfGaz1zwTEHX3Oojbq_pbF3ifPYMYezBU0_pe-_Tg/viewform")
let formSafariView: SFSafariViewController = SFSafariViewController(url: formUrl! as URL)
let reportAction = UIAlertAction(title: "신고하기", style: .destructive, handler: {(_: UIAlertAction!) in
self.present(formSafariView, animated: true, completion: nil)
})
[ reportAction, cancelAction ].forEach { reportAlertController.addAction($0) }
present(reportAlertController, animated: true, completion: nil)
}
Comment on lines +132 to +164
Copy link
Collaborator

Choose a reason for hiding this comment

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

함수가 커지는 것은 지양합시다! -> 함수 내부 코드들을 쪼개서 다른 함수들로 만들고 여기서 호출하는 식으로 각 함수의 역할을 분리하면 좋아요~!
가독성과 유지보수에 큰 영향을 줍니다! (객체지향의 SOLID 원칙에 대해 공부해보면 좋을 것 같아요!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 !!! 지금 당장 해보려고 했으나 급한 불 끄고 깔끔하게 고쳐볼게용

}

private func pushToCountDownVC() {
guard let courseModel = self.courseModel,
let path = courseModel.path,
let distance = courseModel.distance
else { return }

let countDownVC = CountDownVC()
let locations = path.map { NMGLatLng(lat: $0[0], lng: $0[1]) }

let runningModel = RunningModel(courseId: self.courseId,
publicCourseId: self.publicCourseId,
locations: locations,
Expand All @@ -172,12 +195,13 @@ extension CourseDetailVC {
}

func setData(model: UploadedCourseDetailResponseDto) {
self.uploadedCourseDetailModel = model
self.mapImageView.setImage(with: model.publicCourse.image)
self.profileImageView.image = GoalRewardInfoModel.stampNameImageDictionary[model.user.image]
self.profileNameLabel.text = model.user.nickname
self.profileNameLabel.text = model.user.nickname
self.runningLevelLabel.text = "Lv. \(model.user.level)"
self.courseTitleLabel.text = model.publicCourse.title

self.isMyCourse = model.user.isNowUser
guard let scrap = model.publicCourse.scrap else { return }
self.likeButton.isSelected = scrap

Expand Down Expand Up @@ -296,12 +320,12 @@ extension CourseDetailVC {
make.top.equalTo(firstHorizontalDivideLine.snp.bottom).offset(16)
make.leading.equalTo(view.safeAreaLayoutGuide).offset(16)
}

courseDetailStackView.snp.makeConstraints { make in
make.top.equalTo(courseTitleLabel.snp.bottom).offset(19)
make.leading.trailing.equalToSuperview().inset(16)
}

secondHorizontalDivideLine.snp.makeConstraints { make in
make.top.equalTo(courseDetailStackView.snp.bottom).offset(27)
make.leading.trailing.equalTo(view.safeAreaLayoutGuide)
Expand Down Expand Up @@ -398,3 +422,29 @@ extension CourseDetailVC {
}
}
}

extension CourseDetailVC {
private func deleteCourse() {
guard let courseId = self.courseId else { return }
LoadingIndicator.showLoading()
courseProvider.request(.deleteCourse(courseIdList: [courseId])) { [weak self] response in
LoadingIndicator.hideLoading()
guard let self = self else { return }
switch response {
case .success(let result):
print("리절트", result)
let status = result.statusCode
if 200..<300 ~= status {
print("삭제 성공")
}
if status >= 400 {
print("400 error")
self.showNetworkFailureToast()
}
case .failure(let error):
print(error.localizedDescription)
self.showNetworkFailureToast()
}
}
}
}
Loading