-
Notifications
You must be signed in to change notification settings - Fork 6
[Feat] #79 업로드하지 않은 내가 그린 코스 API 연결 #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
The head ref may contain hidden characters: "feat/#79-\uC5C5\uB85C\uB4DC\uD558\uC9C0\uC54A\uC740-\uB0B4\uAC00\uADF8\uB9B0\uCF54\uC2A4-API"
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ct-iOS/Network/Dto/CourseStorageDto/ResponseDto/PrivateCourseNotUploadedResponseDto.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // | ||
| // PrivateCourseNotUploadedResponseDto.swift | ||
| // Runnect-iOS | ||
| // | ||
| // Created by sejin on 2023/01/11. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct PrivateCourseNotUploadedResponseDto: Codable { | ||
| let privateCourses: [Course] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,27 @@ | |
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| import Then | ||
| import Moya | ||
|
|
||
| class MyCourseSelectVC: UIViewController { | ||
|
|
||
| // MARK: - Properties | ||
|
|
||
| private var selectedIndex: Int? | ||
| private let courseStorageProvider = MoyaProvider<CourseStorageRouter>( | ||
| plugins: [NetworkLoggerPlugin(verbose: true)] | ||
| ) | ||
|
|
||
| private var courseList = [Course]() | ||
|
|
||
| private var selectedIndex: Int? { | ||
| didSet { | ||
| if selectedIndex == nil { | ||
| selectButton.setEnabled(false) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // MARK: - UI Components | ||
|
|
||
|
|
@@ -24,7 +38,7 @@ class MyCourseSelectVC: UIViewController { | |
| private lazy var mapCollectionView: UICollectionView = { | ||
| let layout = UICollectionViewFlowLayout() | ||
| layout.scrollDirection = .vertical | ||
|
|
||
| let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) | ||
| collectionView.backgroundColor = .clear | ||
| collectionView.translatesAutoresizingMaskIntoConstraints = false | ||
|
|
@@ -38,7 +52,7 @@ class MyCourseSelectVC: UIViewController { | |
| final let collectionViewInset = UIEdgeInsets(top: 28, left: 16, bottom: 28, right: 16) | ||
| final let itemSpacing: CGFloat = 10 | ||
| final let lineSpacing: CGFloat = 20 | ||
|
|
||
| // MARK: - View Life Cycle | ||
|
|
||
| override func viewDidLoad() { | ||
|
|
@@ -53,53 +67,60 @@ class MyCourseSelectVC: UIViewController { | |
|
|
||
| override func viewWillAppear(_ animated: Bool) { | ||
| self.hideTabBar(wantsToHide: true) | ||
| self.getPrivateCourseNotUploaded() | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Methods | ||
|
|
||
| extension MyCourseSelectVC { | ||
| private func setData(courseList: [Course]) { | ||
| self.courseList = courseList | ||
| mapCollectionView.reloadData() | ||
| } | ||
|
|
||
| private func setDelegate() { | ||
| mapCollectionView.delegate = self | ||
| mapCollectionView.dataSource = self | ||
| } | ||
|
|
||
| private func register() { | ||
| mapCollectionView.register(CourseListCVC.self, | ||
| forCellWithReuseIdentifier: CourseListCVC.className) | ||
| forCellWithReuseIdentifier: CourseListCVC.className) | ||
| } | ||
|
|
||
| private func setAddTarget() { | ||
| self.selectButton.addTarget(self, action: #selector(pushToUploadVC), for: .touchUpInside) | ||
| } | ||
| } | ||
| // MARK: - @objc Function | ||
|
|
||
| extension MyCourseSelectVC { | ||
| @objc private func pushToUploadVC() { | ||
| let nextVC = CourseUploadVC() | ||
| self.navigationController?.pushViewController(nextVC, animated: true) | ||
| } | ||
| // MARK: - @objc Function | ||
|
|
||
| extension MyCourseSelectVC { | ||
| @objc private func pushToUploadVC() { | ||
| guard let selectedIndex = self.selectedIndex else { return } | ||
| let courseUploadVC = CourseUploadVC() | ||
| courseUploadVC.setData(courseModel: courseList[selectedIndex]) | ||
| self.navigationController?.pushViewController(courseUploadVC, animated: true) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - naviVar Layout | ||
| // MARK: - UI & Layout | ||
|
|
||
| extension MyCourseSelectVC { | ||
| private func setNavigationBar() { | ||
| view.addSubview(navibar) | ||
| navibar.snp.makeConstraints { make in | ||
| make.top.leading.trailing.equalTo(view.safeAreaLayoutGuide) | ||
| make.height.equalTo(48) | ||
| } | ||
| } | ||
| } | ||
| // MARK: - setUI | ||
|
|
||
| private func setUI() { | ||
| view.backgroundColor = .w1 | ||
| self.tabBarController?.tabBar.isHidden = true | ||
| } | ||
|
|
||
| // MARK: - Layout Helpers | ||
|
|
||
|
|
||
| private func setLayout() { | ||
| view.addSubviews(selectButton, mapCollectionView) | ||
| self.view.bringSubviewToFront(selectButton) | ||
|
|
@@ -109,7 +130,7 @@ extension MyCourseSelectVC { | |
| make.height.equalTo(44) | ||
| make.bottom.equalToSuperview().inset(34) | ||
| } | ||
|
|
||
| mapCollectionView.snp.makeConstraints { make in | ||
| make.top.equalTo(navibar.snp.bottom) | ||
| make.leading.trailing.equalTo(view.safeAreaLayoutGuide) | ||
|
|
@@ -121,14 +142,16 @@ extension MyCourseSelectVC { | |
|
|
||
| extension MyCourseSelectVC: UICollectionViewDelegate, UICollectionViewDataSource { | ||
| func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
| return 15 | ||
| return courseList.count | ||
| } | ||
|
|
||
| func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | ||
| guard let cell = collectionView.cellForItem(at: indexPath) as? CourseListCVC else { return } | ||
| self.selectedIndex = indexPath.item | ||
| self.selectButton.setEnabled(true) | ||
| cell.selectCell(didSelect: true) | ||
| } | ||
|
|
||
| func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) { | ||
| guard let cell = collectionView.cellForItem(at: indexPath) as? CourseListCVC else { return } | ||
| self.selectedIndex = nil | ||
|
|
@@ -139,14 +162,23 @@ extension MyCourseSelectVC: UICollectionViewDelegate, UICollectionViewDataSource | |
| guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CourseListCVC.className, | ||
| for: indexPath) | ||
| as? CourseListCVC else { return UICollectionViewCell() } | ||
| cell.setCellType(type: .titleWithLocation) | ||
| cell.setCellType(type: .title) | ||
|
|
||
| if let selectedIndex = selectedIndex, selectedIndex == indexPath.item { | ||
| cell.selectCell(didSelect: true) | ||
| } else { | ||
| cell.selectCell(didSelect: false) | ||
| } | ||
|
|
||
| let model = courseList[indexPath.item] | ||
|
|
||
| var title = "\(model.departure.region) \(model.departure.city)" | ||
| if let town = model.departure.town { | ||
| title += " \(town)" | ||
| } | ||
|
|
||
| cell.setData(imageURL: model.image, title: title, location: nil, didLike: nil) | ||
|
|
||
| return cell | ||
| } | ||
| } | ||
|
|
@@ -156,7 +188,7 @@ extension MyCourseSelectVC: UICollectionViewDelegate, UICollectionViewDataSource | |
| extension MyCourseSelectVC: UICollectionViewDelegateFlowLayout { | ||
| func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | ||
| let cellWidth = (UIScreen.main.bounds.width - (self.itemSpacing + 2*self.collectionViewInset.left)) / 2 | ||
| let cellHeight = CourseListCVCType.getCellHeight(type: .titleWithLocation, cellWidth: cellWidth) | ||
| let cellHeight = CourseListCVCType.getCellHeight(type: .title, cellWidth: cellWidth) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 헉 이거 함수 만들었규나 |
||
|
|
||
| return CGSize(width: cellWidth, height: cellHeight) | ||
| } | ||
|
|
@@ -172,5 +204,37 @@ extension MyCourseSelectVC: UICollectionViewDelegateFlowLayout { | |
| func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { | ||
| return self.lineSpacing | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // MARK: - Network | ||
|
|
||
| extension MyCourseSelectVC { | ||
| private func getPrivateCourseNotUploaded() { | ||
| self.selectedIndex = nil | ||
| LoadingIndicator.showLoading() | ||
| courseStorageProvider.request(.getPrivateCourseNotUploaded) { [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<PrivateCourseNotUploadedResponseDto>.self) | ||
| guard let data = responseDto.data else { return } | ||
| self.setData(courseList: data.privateCourses) | ||
| } catch { | ||
| print(error.localizedDescription) | ||
| } | ||
| } | ||
| if status >= 400 { | ||
| print("400 error") | ||
| self.showNetworkFailureToast() | ||
| } | ||
| case .failure(let error): | ||
| print(error.localizedDescription) | ||
| self.showNetworkFailureToast() | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헉.. 계속 attributedString 만들어서 append하고 있었는데.. 이렇게..해야지..나도..