Skip to content

Commit 68dedad

Browse files
authored
Merge pull request #231 from thingineeer/#229--코스발견-서버-API-부분-수정
[Feat] #229 - 코스 상세 스크랩 부분 API 변경으로 인한 코드 추가 구현, 코스 발견 이벤트 추가 작업을 하였습니다.
2 parents 0374a0d + feff494 commit 68dedad

File tree

6 files changed

+59
-13
lines changed

6 files changed

+59
-13
lines changed

Runnect-iOS/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ SPEC CHECKSUMS:
118118

119119
PODFILE CHECKSUM: a1846e0d9fa164fc8d0a63bb343a6b7ba18187b9
120120

121-
COCOAPODS: 1.12.1
121+
COCOAPODS: 1.14.3

Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
7136BF8A2AF921A900679364 /* CustomBottomSheetVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7136BF892AF921A900679364 /* CustomBottomSheetVC.swift */; };
2222
713A98F02B29DD9900189B3C /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 713A98EF2B29DD9900189B3C /* GoogleService-Info.plist */; };
2323
717916DA2B13613B009CEF97 /* MarathonListResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 717916D92B13613B009CEF97 /* MarathonListResponseDto.swift */; };
24+
71802C5C2B3364C2008DBCEE /* CourseDetailScrapCountDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71802C5B2B3364C2008DBCEE /* CourseDetailScrapCountDto.swift */; };
2425
71BAD06A2B24CECC0061E31D /* UserProfileDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71BAD0692B24CECC0061E31D /* UserProfileDto.swift */; };
2526
71BAD06C2B24D1F70061E31D /* UserProfileVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71BAD06B2B24D1F70061E31D /* UserProfileVC.swift */; };
2627
71F7804E2B0893B600B53253 /* MarathonTitleCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71F7804D2B0893B600B53253 /* MarathonTitleCollectionViewCell.swift */; };
@@ -191,6 +192,7 @@
191192
7136BF892AF921A900679364 /* CustomBottomSheetVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomBottomSheetVC.swift; sourceTree = "<group>"; };
192193
713A98EF2B29DD9900189B3C /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
193194
717916D92B13613B009CEF97 /* MarathonListResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarathonListResponseDto.swift; sourceTree = "<group>"; };
195+
71802C5B2B3364C2008DBCEE /* CourseDetailScrapCountDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailScrapCountDto.swift; sourceTree = "<group>"; };
194196
71BAD0692B24CECC0061E31D /* UserProfileDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProfileDto.swift; sourceTree = "<group>"; };
195197
71BAD06B2B24D1F70061E31D /* UserProfileVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProfileVC.swift; sourceTree = "<group>"; };
196198
71F7804D2B0893B600B53253 /* MarathonTitleCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarathonTitleCollectionViewCell.swift; sourceTree = "<group>"; };
@@ -868,6 +870,7 @@
868870
isa = PBXGroup;
869871
children = (
870872
CE4942AC296FCD2300736701 /* UploadedCourseDetailResponseDto.swift */,
873+
71802C5B2B3364C2008DBCEE /* CourseDetailScrapCountDto.swift */,
871874
);
872875
path = ResponseDto;
873876
sourceTree = "<group>";
@@ -1538,6 +1541,7 @@
15381541
CEB8416E2962C45300BF8080 /* LocationSearchResultTVC.swift in Sources */,
15391542
CE102C4829DB1D6B00E23E69 /* GetNewTokenResponseDto.swift in Sources */,
15401543
CE6655CA295D84DD00C64E12 /* UserDefaultKeyList.swift in Sources */,
1544+
71802C5C2B3364C2008DBCEE /* CourseDetailScrapCountDto.swift in Sources */,
15411545
712F661D2A7B7BAB00D9539B /* Config.swift in Sources */,
15421546
23EE06CB2AC2AF3E00CB3FF8 /* KakaoAddressSearchingResponseDto.swift in Sources */,
15431547
CE6655F2295D894D00C64E12 /* UIView+.swift in Sources */,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// CourseDetailScrapCountDto.swift
3+
// Runnect-iOS
4+
//
5+
// Created by 이명진 on 12/21/23.
6+
//
7+
8+
import Foundation
9+
10+
11+
struct CourseDetailScrapCountDto: Codable {
12+
let scrapCount: Int
13+
}

Runnect-iOS/Runnect-iOS/Presentation/CourseDetail/VC/CourseDetailVC.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ final class CourseDetailVC: UIViewController {
2323

2424
// MARK: - Properties
2525

26-
weak var delegate: ScrapStateDelegate?
26+
weak var delegate: ScrapStateDelegate? // 코스 발견 스크랩 이벤트
27+
weak var marathonDelegate: MarathonScrapStateDelegate? // 마라톤 스크랩 이벤트
2728

2829
private let scrapProvider = Providers.scrapProvider
29-
30-
private let PublicCourseProvider = Providers.publicCourseProvider
31-
30+
private let publicCourseProvider = Providers.publicCourseProvider
3231
private let courseProvider = Providers.courseProvider
3332

3433
private var courseModel: Course?
35-
3634
private var uploadedCourseDetailModel: UploadedCourseDetailResponseDto?
3735

3836
private var courseId: Int?
@@ -167,12 +165,9 @@ extension CourseDetailVC {
167165
guard let publicCourseId = publicCourseId else { return }
168166

169167
scrapCourse(scrapTF: !sender.isSelected)
170-
delegate?.didUpdateScrapState(publicCourseId: publicCourseId, isScrapped: !sender.isSelected) /// UI Update 부분
168+
delegate?.didUpdateScrapState(publicCourseId: publicCourseId, isScrapped: !sender.isSelected) /// 코스 발견 UI Update 부분
169+
marathonDelegate?.didUpdateMarathonScrapState(publicCourseId: publicCourseId, isScrapped: !sender.isSelected) // 마라톤 코스 UI Update 부분
171170

172-
/// 누른상태(true)에서 누르면 스크랩 취소(false) 하는 이벤트, 즉 -1
173-
let toggle = sender.isSelected ? -1 : 1
174-
self.scrapCount += toggle
175-
self.scrapCountLabel.text = "\(self.scrapCount)"
176171
/// print("CourseDetailVC 스크랩 탭🔥publicCourseId=\(publicCourseId), isScrapped은 \(!sender.isSelected) 요렇게 변경 ")
177172
}
178173

@@ -509,7 +504,7 @@ extension CourseDetailVC {
509504
private func getUploadedCourseDetail() {
510505
guard let publicCourseId = self.publicCourseId else { return }
511506
LoadingIndicator.showLoading()
512-
PublicCourseProvider.request(.getUploadedCourseDetail(publicCourseId: publicCourseId)) { [weak self] response in
507+
publicCourseProvider.request(.getUploadedCourseDetail(publicCourseId: publicCourseId)) { [weak self] response in
513508
guard let self = self else { return }
514509
LoadingIndicator.hideLoading()
515510
switch response {
@@ -575,7 +570,15 @@ extension CourseDetailVC {
575570
case .success(let result):
576571
let status = result.statusCode
577572
if 200..<300 ~= status {
578-
self.likeButton.isSelected.toggle()
573+
do {
574+
let responseDto = try result.map(BaseResponse<CourseDetailScrapCountDto>.self)
575+
guard let data = responseDto.data else { return }
576+
self.likeButton.isSelected.toggle()
577+
self.scrapCount = data.scrapCount
578+
self.scrapCountLabel.text = "\(self.scrapCount)"
579+
} catch {
580+
print(error.localizedDescription)
581+
}
579582
}
580583
if status >= 400 {
581584
print("400 error")

Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/MarathonMapCollectionViewCell.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import UIKit
99
import Combine
1010

11+
protocol MarathonScrapStateDelegate: AnyObject {
12+
func didUpdateMarathonScrapState(publicCourseId: Int, isScrapped: Bool)
13+
}
14+
1115
class CourseSelectionPublisher {
1216
static let shared = CourseSelectionPublisher()
1317

@@ -68,6 +72,15 @@ extension MarathonMapCollectionViewCell {
6872
marathonCollectionView.register(CourseListCVC.self,
6973
forCellWithReuseIdentifier: CourseListCVC.className)
7074
}
75+
76+
private func marathonReloadCellForCourse(publicCourseId: Int) {
77+
print("✅ 2. \(publicCourseId)번 부분이 교체가 되는가")
78+
if let index = marathonCourseList.firstIndex(where: { $0.id == publicCourseId }) {
79+
let indexPath = IndexPath(item: index, section: 0)
80+
marathonCollectionView.reloadItems(at: [indexPath])
81+
print("✅ 3. \(indexPath) 마라톤 부분 스크랩 교체 되었음 \n reloadItems까지는 작동은 했음 여기서 안되면 코드가 잘 못 된것.")
82+
}
83+
}
7184
}
7285

7386
// MARK: - Layout Helpers
@@ -146,10 +159,22 @@ extension MarathonMapCollectionViewCell: CourseListCVCDeleagte {
146159

147160
let publicCourseId = self.marathonCourseList[index].id
148161
self.scrapCourse(publicCourseId: publicCourseId, scrapTF: wantsTolike)
162+
149163
print("마라톤에 들어온 index = \(index)")
150164
}
151165
}
152166

167+
extension MarathonMapCollectionViewCell: MarathonScrapStateDelegate {
168+
func didUpdateMarathonScrapState(publicCourseId: Int, isScrapped: Bool) {
169+
print("✅ 1. 마라톤 델리게이트 들어오는가 🫶🏻")
170+
if let index = marathonCourseList.firstIndex(where: { $0.id == publicCourseId }) {
171+
marathonCourseList[index].scrap = isScrapped
172+
marathonReloadCellForCourse(publicCourseId: publicCourseId)
173+
print("✅ 4. ‼️MarathonMapCollectionViewCell에서 작업 완료")
174+
}
175+
}
176+
}
177+
153178
// MARK: - NetWork
154179

155180
extension MarathonMapCollectionViewCell {

Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Views/VC/CourseDiscoveryVC.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ extension CourseDiscoveryVC: UICollectionViewDelegateFlowLayout {
339339
if let marathonCell = mapCollectionView.cellForItem(at: IndexPath(item: 0, section: Section.marathonCourseList)) as? MarathonMapCollectionViewCell {
340340
let marathonCourseList = marathonCell.marathonCourseList
341341
let courseDetailVC = CourseDetailVC()
342+
courseDetailVC.marathonDelegate = marathonCell
342343
let courseModel = marathonCourseList[indexPath.item]
343344
courseDetailVC.setCourseId(courseId: courseModel.courseId, publicCourseId: courseModel.id)
344345
courseDetailVC.hidesBottomBarWhenPushed = true

0 commit comments

Comments
 (0)