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 @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Moya

enum MyPageRouter {
case getMyPageInfo
case getUploadedCourseInfo
}

extension MyPageRouter: TargetType {
Expand All @@ -26,27 +27,37 @@ extension MyPageRouter: TargetType {
switch self {
case .getMyPageInfo:
return "/user"
case .getUploadedCourseInfo:
return "/public-course/user"
}
}

var method: Moya.Method {
switch self {
case .getMyPageInfo:
return .get
case .getUploadedCourseInfo:
return .get
}
}

var task: Moya.Task {
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"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
//

import UIKit

import SnapKit
import Then
import Moya
import Kingfisher

final class UploadedCourseInfoCVC: UICollectionViewCell {

Expand All @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyPageRouter>(
plugins: [NetworkLoggerPlugin(verbose: true)]
)

private var uploadedCourseList = [PublicCourse]()

// MARK: - Constants

Expand All @@ -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
}()
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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<PickedMapListResponseDto>.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()
}
}
}
}