diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/ResponseDto/PickedMapListResponseDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/ResponseDto/PickedMapListResponseDto.swift index ed5b0f09..7e23d96c 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/ResponseDto/PickedMapListResponseDto.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/ResponseDto/PickedMapListResponseDto.swift @@ -19,7 +19,7 @@ struct PublicCourse: Codable { let id, courseId: Int let title: String let image: String - let scarp: Bool + let scarp: Bool? let departure: CourseDiscoveryDeparture } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift index df667025..54728c92 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift @@ -11,6 +11,7 @@ import Moya enum MyPageRouter { case getMyPageInfo + case getUploadedCourseInfo } extension MyPageRouter: TargetType { @@ -26,6 +27,8 @@ extension MyPageRouter: TargetType { switch self { case .getMyPageInfo: return "/user" + case .getUploadedCourseInfo: + return "/public-course/user" } } @@ -33,6 +36,8 @@ extension MyPageRouter: TargetType { switch self { case .getMyPageInfo: return .get + case .getUploadedCourseInfo: + return .get } } @@ -40,13 +45,19 @@ extension MyPageRouter: TargetType { switch self { case .getMyPageInfo: return .requestPlain + case .getUploadedCourseInfo: + return .requestPlain } } var headers: [String: String]? { switch self { case .getMyPageInfo: - return Config.headerWithDeviceId + return ["Content-Type": "application/json", + "machineId": "1"] + case .getUploadedCourseInfo: + return ["Content-Type": "application/json", + "machineId": "1"] } } } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoCollectionView/UploadedCourseInfoCVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoCollectionView/UploadedCourseInfoCVC.swift index c31435dd..8ac48bfd 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoCollectionView/UploadedCourseInfoCVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoCollectionView/UploadedCourseInfoCVC.swift @@ -6,8 +6,11 @@ // import UIKit + import SnapKit import Then +import Moya +import Kingfisher final class UploadedCourseInfoCVC: UICollectionViewCell { @@ -22,10 +25,7 @@ final class UploadedCourseInfoCVC: UICollectionViewCell { $0.font = .b4 } - private let uploadedCoursePlaceLabel = UILabel().then { - $0.textColor = .g2 - $0.font = .b6 - } + private let uploadedCoursePlaceLabel = UILabel() // MARK: - Life Cycles @@ -40,6 +40,24 @@ final class UploadedCourseInfoCVC: UICollectionViewCell { } } +// MARK: - Methods + +extension UploadedCourseInfoCVC { + func setData(model: PublicCourse) { + guard let imageURL = URL(string: model.image) else { return } + + uploadedCourseTitleLabel.text = model.title + setUploadedCoursePlaceLabel(model: model, label: uploadedCoursePlaceLabel) + self.uploadedCourseMapImage.kf.setImage(with: imageURL) + } + + func setUploadedCoursePlaceLabel(model: PublicCourse, label: UILabel) { + let attributedString = NSMutableAttributedString(string: String(model.departure.region) + " ", attributes: [.font: UIFont.b6, .foregroundColor: UIColor.g2]) + attributedString.append(NSAttributedString(string: String(model.departure.city), attributes: [.font: UIFont.b6, .foregroundColor: UIColor.g2])) + label.attributedText = attributedString + } +} + extension UploadedCourseInfoCVC { // MARK: - Layout Helpers diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoVC.swift index 854aacf2..f2164e40 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoVC.swift @@ -6,24 +6,20 @@ // import UIKit + import SnapKit import Then +import Moya final class UploadedCourseInfoVC: UIViewController { // MARK: - Properties - var UploadedCourseList: [UploadedCourseInfoModel] = [ - UploadedCourseInfoModel(title: "행복한 날들", place: "수원시 장안구"), - UploadedCourseInfoModel(title: "몽이랑 산책", place: "수원시 장안구"), - UploadedCourseInfoModel(title: "패스트파이브", place: "수원시 장안구"), - UploadedCourseInfoModel(title: "행복한 날들", place: "수원시 장안구"), - UploadedCourseInfoModel(title: "몽이랑 산책", place: "수원시 장안구"), - UploadedCourseInfoModel(title: "패스트파이브", place: "수원시 장안구"), - UploadedCourseInfoModel(title: "행복한 날들", place: "수원시 장안구"), - UploadedCourseInfoModel(title: "몽이랑 산책", place: "수원시 장안구"), - UploadedCourseInfoModel(title: "패스트파이브", place: "수원시 장안구") - ] + private var uploadedCourseProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) + + private var uploadedCourseList = [PublicCourse]() // MARK: - Constants @@ -43,8 +39,6 @@ final class UploadedCourseInfoVC: UIViewController { let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) collectionView.isScrollEnabled = true collectionView.showsVerticalScrollIndicator = false - collectionView.delegate = self - collectionView.dataSource = self return collectionView }() @@ -57,6 +51,27 @@ final class UploadedCourseInfoVC: UIViewController { setUI() setLayout() register() + setDelegate() + getUploadedCourseInfo() + } +} + +// MARK: - Methods + +extension UploadedCourseInfoVC { + private func setData(courseList: [PublicCourse]) { + self.uploadedCourseList = courseList + UploadedCourseInfoCollectionView.reloadData() + } + + private func setDelegate() { + self.UploadedCourseInfoCollectionView.delegate = self + self.UploadedCourseInfoCollectionView.dataSource = self + } + + private func register() { + UploadedCourseInfoCollectionView.register(UploadedCourseInfoCVC.self, + forCellWithReuseIdentifier: UploadedCourseInfoCVC.className) } } @@ -87,13 +102,6 @@ extension UploadedCourseInfoVC { make.bottom.equalTo(view.safeAreaLayoutGuide) } } - - // MARK: - General Helpers - - private func register() { - UploadedCourseInfoCollectionView.register(UploadedCourseInfoCVC.self, - forCellWithReuseIdentifier: UploadedCourseInfoCVC.className) - } } // MARK: - UICollectionViewDelegateFlowLayout @@ -119,12 +127,44 @@ extension UploadedCourseInfoVC: UICollectionViewDelegateFlowLayout { extension UploadedCourseInfoVC: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return UploadedCourseList.count + return uploadedCourseList.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { guard let uploadedCourseCell = collectionView.dequeueReusableCell(withReuseIdentifier: UploadedCourseInfoCVC.className, for: indexPath) as? UploadedCourseInfoCVC else { return UICollectionViewCell()} - uploadedCourseCell.dataBind(model: UploadedCourseList[indexPath.item]) + uploadedCourseCell.setData(model: uploadedCourseList[indexPath.item]) return uploadedCourseCell } } + +// MARK: - Network + +extension UploadedCourseInfoVC { + func getUploadedCourseInfo() { + LoadingIndicator.showLoading() + uploadedCourseProvider.request(.getUploadedCourseInfo) { [weak self] response in + LoadingIndicator.hideLoading() + 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(BaseResponse.self) + guard let data = responseDto.data else { return } + self.setData(courseList: data.publicCourses) + } catch { + print(error.localizedDescription) + } + } + if status >= 400 { + print("400 error") + self.showNetworkFailureToast() + } + case .failure(let error): + print(error.localizedDescription) + self.showNetworkFailureToast() + } + } + } +}