Skip to content

Commit 6cfdfe0

Browse files
authored
Merge pull request #75 from dlwogus0128/feat/#73-업로드한-코스-API-연결
[Feat] #73 - 업로드한 코스 API 연결
2 parents b2eb0fa + 335a993 commit 6cfdfe0

File tree

4 files changed

+97
-28
lines changed

4 files changed

+97
-28
lines changed

Runnect-iOS/Runnect-iOS/Network/Dto/CourseDiscoveryDto/ResponseDto/PickedMapListResponseDto.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct PublicCourse: Codable {
1919
let id, courseId: Int
2020
let title: String
2121
let image: String
22-
let scarp: Bool
22+
let scarp: Bool?
2323
let departure: CourseDiscoveryDeparture
2424
}
2525

Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Moya
1111

1212
enum MyPageRouter {
1313
case getMyPageInfo
14+
case getUploadedCourseInfo
1415
}
1516

1617
extension MyPageRouter: TargetType {
@@ -26,27 +27,37 @@ extension MyPageRouter: TargetType {
2627
switch self {
2728
case .getMyPageInfo:
2829
return "/user"
30+
case .getUploadedCourseInfo:
31+
return "/public-course/user"
2932
}
3033
}
3134

3235
var method: Moya.Method {
3336
switch self {
3437
case .getMyPageInfo:
3538
return .get
39+
case .getUploadedCourseInfo:
40+
return .get
3641
}
3742
}
3843

3944
var task: Moya.Task {
4045
switch self {
4146
case .getMyPageInfo:
4247
return .requestPlain
48+
case .getUploadedCourseInfo:
49+
return .requestPlain
4350
}
4451
}
4552

4653
var headers: [String: String]? {
4754
switch self {
4855
case .getMyPageInfo:
49-
return Config.headerWithDeviceId
56+
return ["Content-Type": "application/json",
57+
"machineId": "1"]
58+
case .getUploadedCourseInfo:
59+
return ["Content-Type": "application/json",
60+
"machineId": "1"]
5061
}
5162
}
5263
}

Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoCollectionView/UploadedCourseInfoCVC.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
//
77

88
import UIKit
9+
910
import SnapKit
1011
import Then
12+
import Moya
13+
import Kingfisher
1114

1215
final class UploadedCourseInfoCVC: UICollectionViewCell {
1316

@@ -22,10 +25,7 @@ final class UploadedCourseInfoCVC: UICollectionViewCell {
2225
$0.font = .b4
2326
}
2427

25-
private let uploadedCoursePlaceLabel = UILabel().then {
26-
$0.textColor = .g2
27-
$0.font = .b6
28-
}
28+
private let uploadedCoursePlaceLabel = UILabel()
2929

3030
// MARK: - Life Cycles
3131

@@ -40,6 +40,24 @@ final class UploadedCourseInfoCVC: UICollectionViewCell {
4040
}
4141
}
4242

43+
// MARK: - Methods
44+
45+
extension UploadedCourseInfoCVC {
46+
func setData(model: PublicCourse) {
47+
guard let imageURL = URL(string: model.image) else { return }
48+
49+
uploadedCourseTitleLabel.text = model.title
50+
setUploadedCoursePlaceLabel(model: model, label: uploadedCoursePlaceLabel)
51+
self.uploadedCourseMapImage.kf.setImage(with: imageURL)
52+
}
53+
54+
func setUploadedCoursePlaceLabel(model: PublicCourse, label: UILabel) {
55+
let attributedString = NSMutableAttributedString(string: String(model.departure.region) + " ", attributes: [.font: UIFont.b6, .foregroundColor: UIColor.g2])
56+
attributedString.append(NSAttributedString(string: String(model.departure.city), attributes: [.font: UIFont.b6, .foregroundColor: UIColor.g2]))
57+
label.attributedText = attributedString
58+
}
59+
}
60+
4361
extension UploadedCourseInfoCVC {
4462

4563
// MARK: - Layout Helpers

Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoVC.swift

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,20 @@
66
//
77

88
import UIKit
9+
910
import SnapKit
1011
import Then
12+
import Moya
1113

1214
final class UploadedCourseInfoVC: UIViewController {
1315

1416
// MARK: - Properties
1517

16-
var UploadedCourseList: [UploadedCourseInfoModel] = [
17-
UploadedCourseInfoModel(title: "행복한 날들", place: "수원시 장안구"),
18-
UploadedCourseInfoModel(title: "몽이랑 산책", place: "수원시 장안구"),
19-
UploadedCourseInfoModel(title: "패스트파이브", place: "수원시 장안구"),
20-
UploadedCourseInfoModel(title: "행복한 날들", place: "수원시 장안구"),
21-
UploadedCourseInfoModel(title: "몽이랑 산책", place: "수원시 장안구"),
22-
UploadedCourseInfoModel(title: "패스트파이브", place: "수원시 장안구"),
23-
UploadedCourseInfoModel(title: "행복한 날들", place: "수원시 장안구"),
24-
UploadedCourseInfoModel(title: "몽이랑 산책", place: "수원시 장안구"),
25-
UploadedCourseInfoModel(title: "패스트파이브", place: "수원시 장안구")
26-
]
18+
private var uploadedCourseProvider = MoyaProvider<MyPageRouter>(
19+
plugins: [NetworkLoggerPlugin(verbose: true)]
20+
)
21+
22+
private var uploadedCourseList = [PublicCourse]()
2723

2824
// MARK: - Constants
2925

@@ -43,8 +39,6 @@ final class UploadedCourseInfoVC: UIViewController {
4339
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
4440
collectionView.isScrollEnabled = true
4541
collectionView.showsVerticalScrollIndicator = false
46-
collectionView.delegate = self
47-
collectionView.dataSource = self
4842

4943
return collectionView
5044
}()
@@ -57,6 +51,27 @@ final class UploadedCourseInfoVC: UIViewController {
5751
setUI()
5852
setLayout()
5953
register()
54+
setDelegate()
55+
getUploadedCourseInfo()
56+
}
57+
}
58+
59+
// MARK: - Methods
60+
61+
extension UploadedCourseInfoVC {
62+
private func setData(courseList: [PublicCourse]) {
63+
self.uploadedCourseList = courseList
64+
UploadedCourseInfoCollectionView.reloadData()
65+
}
66+
67+
private func setDelegate() {
68+
self.UploadedCourseInfoCollectionView.delegate = self
69+
self.UploadedCourseInfoCollectionView.dataSource = self
70+
}
71+
72+
private func register() {
73+
UploadedCourseInfoCollectionView.register(UploadedCourseInfoCVC.self,
74+
forCellWithReuseIdentifier: UploadedCourseInfoCVC.className)
6075
}
6176
}
6277

@@ -87,13 +102,6 @@ extension UploadedCourseInfoVC {
87102
make.bottom.equalTo(view.safeAreaLayoutGuide)
88103
}
89104
}
90-
91-
// MARK: - General Helpers
92-
93-
private func register() {
94-
UploadedCourseInfoCollectionView.register(UploadedCourseInfoCVC.self,
95-
forCellWithReuseIdentifier: UploadedCourseInfoCVC.className)
96-
}
97105
}
98106

99107
// MARK: - UICollectionViewDelegateFlowLayout
@@ -119,12 +127,44 @@ extension UploadedCourseInfoVC: UICollectionViewDelegateFlowLayout {
119127

120128
extension UploadedCourseInfoVC: UICollectionViewDataSource {
121129
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
122-
return UploadedCourseList.count
130+
return uploadedCourseList.count
123131
}
124132

125133
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
126134
guard let uploadedCourseCell = collectionView.dequeueReusableCell(withReuseIdentifier: UploadedCourseInfoCVC.className, for: indexPath) as? UploadedCourseInfoCVC else { return UICollectionViewCell()}
127-
uploadedCourseCell.dataBind(model: UploadedCourseList[indexPath.item])
135+
uploadedCourseCell.setData(model: uploadedCourseList[indexPath.item])
128136
return uploadedCourseCell
129137
}
130138
}
139+
140+
// MARK: - Network
141+
142+
extension UploadedCourseInfoVC {
143+
func getUploadedCourseInfo() {
144+
LoadingIndicator.showLoading()
145+
uploadedCourseProvider.request(.getUploadedCourseInfo) { [weak self] response in
146+
LoadingIndicator.hideLoading()
147+
guard let self = self else { return }
148+
switch response {
149+
case .success(let result):
150+
let status = result.statusCode
151+
if 200..<300 ~= status {
152+
do {
153+
let responseDto = try result.map(BaseResponse<PickedMapListResponseDto>.self)
154+
guard let data = responseDto.data else { return }
155+
self.setData(courseList: data.publicCourses)
156+
} catch {
157+
print(error.localizedDescription)
158+
}
159+
}
160+
if status >= 400 {
161+
print("400 error")
162+
self.showNetworkFailureToast()
163+
}
164+
case .failure(let error):
165+
print(error.localizedDescription)
166+
self.showNetworkFailureToast()
167+
}
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)