@@ -25,9 +25,11 @@ final class CourseDetailVC: UIViewController {
2525
2626 private var courseModel : Course ?
2727
28+ private var uploadedCourseDetailModel : UploadedCourseDetailResponseDto ?
29+
2830 private var courseId : Int ?
2931 private var publicCourseId : Int ?
30- private var userId : Int ?
32+ private var isMyCourse : Bool ?
3133
3234 // MARK: - UI Components
3335 private lazy var navibar = CustomNavigationBar ( self , type: . titleWithLeftButton)
@@ -80,7 +82,7 @@ final class CourseDetailVC: UIViewController {
8082 $0. textColor = . g1
8183 $0. font = . h4
8284 }
83-
85+
8486 private let courseDistanceInfoView = CourseDetailInfoView ( title: " 거리 " , description: " 0.0km " )
8587
8688 private let courseDepartureInfoView = CourseDetailInfoView ( title: " 출발지 " , description: " 위치 " )
@@ -103,7 +105,7 @@ final class CourseDetailVC: UIViewController {
103105 $0. sizeToFit ( )
104106 }
105107 // MARK: - View Life Cycle
106-
108+
107109 override func viewDidLoad( ) {
108110 super. viewDidLoad ( )
109111 setNavigationBar ( )
@@ -127,44 +129,49 @@ extension CourseDetailVC {
127129 }
128130
129131 @objc func moreButtonDidTap( ) {
130- //Todo : case를 2개를 나눠서, userID가 나인경우에는 editAction,이외에는 신고액션
131- // 삭제 & 수정 올라오는거(유저아이디가 나인경우)
132- //UploadedCourseDetailResponseDto 에서 유저정보 가져오는 법
133- let userId = " " //본인아이디
132+ guard let isMyCourse = self . isMyCourse, let uploadedCourseDetailModel = self . uploadedCourseDetailModel else { return }
133+
134134 let cancelAction = UIAlertAction ( title: " 닫기 " , style: . cancel, handler: nil )
135- if " 유저아이디 " == " 본인아이디 " {
136- let editAlertController = UIAlertController ( title: nil , message: nil , preferredStyle: . actionSheet)
137- let courseUploadVC = CourseUploadVC ( )
138- let editAction = UIAlertAction ( title: " 수정하기 " , style: . destructive, handler: { ( _: UIAlertAction!) in
139- self . present ( courseUploadVC, animated: true , completion: nil )
140- } )
141- let delateAction = UIAlertAction ( title: " 삭제하기 " , style: . cancel, handler: nil )
142- [ editAction, delateAction, cancelAction] . forEach { editAlertController. addAction ( $0) }
143- present ( editAlertController, animated: true , completion: nil )
144-
145- } else {
146- // 신고폼 올라오는 거(유저아이디가 내가 아닌 경우)
147- let reportAlertController = UIAlertController ( title: nil , message: nil , preferredStyle: . actionSheet)
148- let formUrl = NSURL ( string: " https://docs.google.com/forms/d/e/1FAIpQLSek2rkClKfGaz1zwTEHX3Oojbq_pbF3ifPYMYezBU0_pe-_Tg/viewform " )
149- let formSafariView : SFSafariViewController = SFSafariViewController ( url: formUrl! as URL )
150- let reportAction = UIAlertAction ( title: " 신고하기 " , style: . destructive, handler: { ( _: UIAlertAction!) in
151- self . present ( formSafariView, animated: true , completion: nil )
152- } )
153- [ reportAction, cancelAction ] . forEach { reportAlertController. addAction ( $0) }
154- present ( reportAlertController, animated: true , completion: nil )
155- }
156- } ;
157135
136+ if isMyCourse == true {
137+ let editAlertController = UIAlertController ( title: nil , message: nil , preferredStyle: . actionSheet)
138+ let courseEditVC = CourseEditVC ( )
139+ courseEditVC. loadData ( model: uploadedCourseDetailModel)
140+ courseEditVC. publicCourseId = self . publicCourseId
141+ let editAction = UIAlertAction ( title: " 수정하기 " , style: . default, handler: { ( _: UIAlertAction!) in
142+ self . navigationController? . pushViewController ( courseEditVC, animated: false )
143+ } )
144+ let delateVC = RNAlertVC ( description: " 코스를 정말로 삭제하시겠어요? " )
145+ delateVC. rightButtonTapAction = { [ weak self] in
146+ // self?.delateCourse()
147+ }
148+ delateVC. modalPresentationStyle = . overFullScreen
149+ let delateAction = UIAlertAction ( title: " 삭제하기 " , style: . destructive, handler: { ( _: UIAlertAction!) in
150+ self . present ( delateVC, animated: true , completion: nil ) } )
151+ [ editAction, delateAction, cancelAction] . forEach { editAlertController. addAction ( $0) }
152+ present ( editAlertController, animated: false , completion: nil )
153+ } else {
154+ // 신고폼 올라오는 거(유저아이디가 내가 아닌 경우)
155+ let reportAlertController = UIAlertController ( title: nil , message: nil , preferredStyle: . actionSheet)
156+ let formUrl = NSURL ( string: " https://docs.google.com/forms/d/e/1FAIpQLSek2rkClKfGaz1zwTEHX3Oojbq_pbF3ifPYMYezBU0_pe-_Tg/viewform " )
157+ let formSafariView : SFSafariViewController = SFSafariViewController ( url: formUrl! as URL )
158+ let reportAction = UIAlertAction ( title: " 신고하기 " , style: . destructive, handler: { ( _: UIAlertAction!) in
159+ self . present ( formSafariView, animated: true , completion: nil )
160+ } )
161+ [ reportAction, cancelAction ] . forEach { reportAlertController. addAction ( $0) }
162+ present ( reportAlertController, animated: true , completion: nil )
163+ }
164+ }
158165
159166 private func pushToCountDownVC( ) {
160167 guard let courseModel = self . courseModel,
161168 let path = courseModel. path,
162169 let distance = courseModel. distance
163170 else { return }
164-
171+
165172 let countDownVC = CountDownVC ( )
166173 let locations = path. map { NMGLatLng ( lat: $0 [ 0 ] , lng: $0 [ 1 ] ) }
167-
174+
168175 let runningModel = RunningModel ( courseId: self . courseId,
169176 publicCourseId: self . publicCourseId,
170177 locations: locations,
@@ -187,11 +194,13 @@ extension CourseDetailVC {
187194 }
188195
189196 func setData( model: UploadedCourseDetailResponseDto ) {
197+ self . uploadedCourseDetailModel = model
190198 self . mapImageView. setImage ( with: model. publicCourse. image)
191199 self . profileImageView. image = GoalRewardInfoModel . stampNameImageDictionary [ model. user. image]
192200 self . profileNameLabel. text = model. user. nickname //유저닉네임
193201 self . runningLevelLabel. text = " Lv. \( model. user. level) "
194202 self . courseTitleLabel. text = model. publicCourse. title
203+ self . isMyCourse = model. user. isNowUser
195204 guard let scrap = model. publicCourse. scrap else { return }
196205 self . likeButton. isSelected = scrap
197206
@@ -310,12 +319,12 @@ extension CourseDetailVC {
310319 make. top. equalTo ( firstHorizontalDivideLine. snp. bottom) . offset ( 16 )
311320 make. leading. equalTo ( view. safeAreaLayoutGuide) . offset ( 16 )
312321 }
313-
322+
314323 courseDetailStackView. snp. makeConstraints { make in
315324 make. top. equalTo ( courseTitleLabel. snp. bottom) . offset ( 19 )
316325 make. leading. trailing. equalToSuperview ( ) . inset ( 16 )
317326 }
318-
327+
319328 secondHorizontalDivideLine. snp. makeConstraints { make in
320329 make. top. equalTo ( courseDetailStackView. snp. bottom) . offset ( 27 )
321330 make. leading. trailing. equalTo ( view. safeAreaLayoutGuide)
@@ -412,3 +421,32 @@ extension CourseDetailVC {
412421 }
413422 }
414423}
424+
425+ extension CourseDetailVC {
426+ private func delateCourse( ) {
427+ // guard let courseId = courseModel?.id else { return }
428+ // let requsetDto = CourseUploadingRequestDto(courseId: courseId, title: titletext, description: descriptiontext)
429+ //
430+ // LoadingIndicator.showLoading()
431+ // PublicCourseProvider.request(.courseUploadingData(param: requsetDto)) { [weak self] response in
432+ // LoadingIndicator.hideLoading()
433+ // guard let self = self else { return }
434+ // switch response {
435+ // case .success(let result):
436+ // let status = result.statusCode
437+ // if 200..<300 ~= status {
438+ // self.navigationController?.popToRootViewController(animated: true)
439+ // }
440+ // if status >= 400 {
441+ // print("400 error")
442+ // self.showNetworkFailureToast()
443+ // }
444+ // case .failure(let error):
445+ // print(error.localizedDescription)
446+ // self.showNetworkFailureToast()
447+ // }
448+ // }
449+ // }
450+ // }
451+ }
452+ }
0 commit comments