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
4 changes: 4 additions & 0 deletions Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
A3F67AE2296D33AC001598A2 /* MyPageDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE1296D33AC001598A2 /* MyPageDto.swift */; };
A3F67AE4296D33E0001598A2 /* MyPageRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */; };
A3F67AEA296E4936001598A2 /* ActivityRecordInfoDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE9296E4936001598A2 /* ActivityRecordInfoDto.swift */; };
CE09037D296E9ED900BEA710 /* ScrapCourseResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE09037C296E9ED900BEA710 /* ScrapCourseResponseDto.swift */; };
CE0C23742966D62A00B45063 /* PagedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0C23732966D62A00B45063 /* PagedView.swift */; };
CE0C23772966D64D00B45063 /* PageCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0C23762966D64D00B45063 /* PageCVC.swift */; };
CE0C23792966D6AF00B45063 /* ViewPager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0C23782966D6AF00B45063 /* ViewPager.swift */; };
Expand Down Expand Up @@ -158,6 +159,7 @@
A3F67AE1296D33AC001598A2 /* MyPageDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageDto.swift; sourceTree = "<group>"; };
A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageRouter.swift; sourceTree = "<group>"; };
A3F67AE9296E4936001598A2 /* ActivityRecordInfoDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityRecordInfoDto.swift; sourceTree = "<group>"; };
CE09037C296E9ED900BEA710 /* ScrapCourseResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrapCourseResponseDto.swift; sourceTree = "<group>"; };
CE0C23732966D62A00B45063 /* PagedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagedView.swift; sourceTree = "<group>"; };
CE0C23762966D64D00B45063 /* PageCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageCVC.swift; sourceTree = "<group>"; };
CE0C23782966D6AF00B45063 /* ViewPager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -831,6 +833,7 @@
children = (
CE591EA0296D5EB5000FCBB3 /* PrivateCourseResponseDto.swift */,
CECA695B296E61D6002AF05C /* PrivateCourseNotUploadedResponseDto.swift */,
CE09037C296E9ED900BEA710 /* ScrapCourseResponseDto.swift */,
);
path = ResponseDto;
sourceTree = "<group>";
Expand Down Expand Up @@ -1400,6 +1403,7 @@
CE3A53C5296C6017003D518C /* KeychainManager.swift in Sources */,
CE14677A2965A80700DCEA1B /* CustomBottomSheetVC.swift in Sources */,
CEEC6B4B2961D89700D00E1E /* CustomNavigationBar.swift in Sources */,
CE09037D296E9ED900BEA710 /* ScrapCourseResponseDto.swift in Sources */,
CE40BB2D296808B00030ABCA /* DepartureSearchingRouter.swift in Sources */,
CE15F5A4296C932E0023827C /* RunningModel.swift in Sources */,
CE17F02D2961BBA100E1DED0 /* ColorLiterals.swift in Sources */,
Expand Down
12 changes: 12 additions & 0 deletions Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ extension CustomButton {
return self
}

@discardableResult
public func setTitle(title: String) -> Self {
self.setAttributedTitle(
NSAttributedString(
string: title,
attributes: [.font: UIFont.h5, .foregroundColor: UIColor.white]
),
for: .normal
)
return self
}

/// 버튼의 backgroundColor, textColor 변경
@discardableResult
public func setColor(bgColor: UIColor, disableColor: UIColor, textColor: UIColor = .white) -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extension ListEmptyView {
self.backgroundColor = .clear

self.descriptionLabel.text = description
self.bottomButton.titleLabel?.text = buttonTitle
self.bottomButton.setTitle(title: buttonTitle)
}

private func setLayout() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ScrapCourseResponseDto.swift
// Runnect-iOS
//
// Created by sejin on 2023/01/11.
//

import Foundation

// MARK: - ScrapCourseResponseDto

struct ScrapCourseResponseDto: Codable {
let scraps: [ScrapCourse]

enum CodingKeys: String, CodingKey {
case scraps = "Scraps"
}
}

// MARK: - ScrapCourse

struct ScrapCourse: Codable {
let id, publicCourseId, courseId: Int
let title: String
let image: String
let departure: ScrapCourseDeparture
}

// MARK: - ScrapCourseDeparture

struct ScrapCourseDeparture: Codable {
let region, city: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Moya
enum CourseStorageRouter {
case getAllPrivateCourse
case getPrivateCourseNotUploaded
case getScrapCourse
}

extension CourseStorageRouter: TargetType {
Expand All @@ -29,26 +30,28 @@ extension CourseStorageRouter: TargetType {
return "/course/user"
case .getPrivateCourseNotUploaded:
return "/course/private/user"
case .getScrapCourse:
return "/scrap/user"
}
}

var method: Moya.Method {
switch self {
case .getAllPrivateCourse, .getPrivateCourseNotUploaded:
case .getAllPrivateCourse, .getPrivateCourseNotUploaded, .getScrapCourse:
return .get
}
}

var task: Moya.Task {
switch self {
case .getAllPrivateCourse, .getPrivateCourseNotUploaded:
case .getAllPrivateCourse, .getPrivateCourseNotUploaded, .getScrapCourse:
return .requestPlain
}
}

var headers: [String: String]? {
switch self {
case .getAllPrivateCourse, .getPrivateCourseNotUploaded:
case .getAllPrivateCourse, .getPrivateCourseNotUploaded, .getScrapCourse:
return Config.headerWithDeviceId
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import Then

final class CourseDetailVC: UIViewController {

// MARK: - Properties

private var courseId: Int?
private var publicCourseId: Int?

// MARK: - UI Components
private lazy var navibar = CustomNavigationBar(self, type: .titleWithLeftButton)
private lazy var middleScorollView = UIScrollView().then {
Expand Down Expand Up @@ -112,6 +117,11 @@ extension CourseDetailVC {
// MARK: - Method

extension CourseDetailVC {
func setCourseId(courseId: Int?, publicCourseId: Int?) {
self.courseId = courseId
self.publicCourseId = publicCourseId
}

private func setAddTarget() {
likeButton.addTarget(self, action: #selector(likeButtonDidTap), for: .touchUpInside)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ final class CourseStorageVC: UIViewController {

private var privateCourseList = [PrivateCourse]()

private var scrapCourseList = [ScrapCourse]()

// MARK: - UI Components

private lazy var naviBar = CustomNavigationBar(self, type: .title).setTitle("보관함")
Expand All @@ -45,6 +47,7 @@ final class CourseStorageVC: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.getPrivateCourseList()
self.getScrapCourseList()
}
}

Expand All @@ -56,6 +59,11 @@ extension CourseStorageVC {
self.privateCourseListView.setData(courseList: courseList)
}

private func setScrapCourseData(courseList: [ScrapCourse]) {
self.scrapCourseList = courseList
self.scrapCourseListView.setData(courseList: courseList)
}

private func bindUI() {
privateCourseListView.courseDrawButtonTapped.sink { [weak self] in
guard let self = self else { return }
Expand All @@ -78,6 +86,8 @@ extension CourseStorageVC {
scrapCourseListView.cellDidTapped.sink { [weak self] index in
guard let self = self else { return }
let courseDetailVC = CourseDetailVC()
let model = self.scrapCourseList[index]
courseDetailVC.setCourseId(courseId: model.courseId, publicCourseId: model.publicCourseId)
courseDetailVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(courseDetailVC, animated: true)
}.store(in: cancelBag)
Expand Down Expand Up @@ -136,4 +146,32 @@ extension CourseStorageVC {
}
}
}

private func getScrapCourseList() {
LoadingIndicator.showLoading()
courseStorageProvider.request(.getScrapCourse) { [weak self] response in
guard let self = self else { return }
LoadingIndicator.hideLoading()
switch response {
case .success(let result):
let status = result.statusCode
if 200..<300 ~= status {
do {
let responseDto = try result.map(BaseResponse<ScrapCourseResponseDto>.self)
guard let data = responseDto.data else { return }
self.setScrapCourseData(courseList: data.scraps)
} catch {
print(error.localizedDescription)
}
}
if status >= 400 {
print("400 error")
self.showNetworkFailureToast()
}
case .failure(let error):
print(error.localizedDescription)
self.showNetworkFailureToast()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ final class ScrapCourseListView: UIView {
var scrapButtonTapped = PassthroughSubject<Void, Never>()
var cellDidTapped = PassthroughSubject<Int, Never>()

private var courseList = [ScrapCourse]()

final let collectionViewInset = UIEdgeInsets(top: 28, left: 16, bottom: 28, right: 16)
final let itemSpacing: CGFloat = 10
final let lineSpacing: CGFloat = 20
Expand Down Expand Up @@ -53,6 +55,12 @@ final class ScrapCourseListView: UIView {
// MARK: - Methods

extension ScrapCourseListView {
func setData(courseList: [ScrapCourse]) {
self.courseList = courseList
self.courseListCollectionView.reloadData()
self.emptyView.isHidden = !courseList.isEmpty
}

private func setDelegate() {
courseListCollectionView.delegate = self
courseListCollectionView.dataSource = self
Expand Down Expand Up @@ -94,14 +102,20 @@ extension ScrapCourseListView {

extension ScrapCourseListView: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 15
return courseList.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CourseListCVC.className,
for: indexPath)
as? CourseListCVC else { return UICollectionViewCell() }
cell.setCellType(type: .all)

let model = courseList[indexPath.item]

let location = "\(model.departure.region) \(model.departure.city)"

cell.setData(imageURL: model.image, title: model.title, location: location, didLike: true)
return cell
}
}
Expand Down