From 4cd34ceca30db78de9522b4d5bf7c47d80c0c04e Mon Sep 17 00:00:00 2001 From: peng-u-0807 Date: Tue, 13 Aug 2024 20:27:45 +0900 Subject: [PATCH] Fix fetching evLecture id --- SNUTT-2022/SNUTT/Services/LectureService.swift | 8 +++----- .../SNUTT/Views/Scenes/LectureDetailScene.swift | 16 ++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/SNUTT-2022/SNUTT/Services/LectureService.swift b/SNUTT-2022/SNUTT/Services/LectureService.swift index 7663a712..d17bdda1 100644 --- a/SNUTT-2022/SNUTT/Services/LectureService.swift +++ b/SNUTT-2022/SNUTT/Services/LectureService.swift @@ -99,11 +99,9 @@ struct LectureService: LectureServiceProtocol { } func getEvLecture(of lecture: Lecture) async throws -> EvLecture? { - if let lectureId = lecture.lectureId { - let dto = try await reviewRepository.fetchEvLectureInfo(lectureId: lectureId) - return .init(from: dto) - } - return nil + let lectureId = lecture.lectureId ?? lecture.id + let dto = try await reviewRepository.fetchEvLectureInfo(lectureId: lectureId) + return .init(from: dto) } func getBuildingList(of lecture: Lecture) async throws -> [Building] { diff --git a/SNUTT-2022/SNUTT/Views/Scenes/LectureDetailScene.swift b/SNUTT-2022/SNUTT/Views/Scenes/LectureDetailScene.swift index 05724267..c6cf12fd 100644 --- a/SNUTT-2022/SNUTT/Views/Scenes/LectureDetailScene.swift +++ b/SNUTT-2022/SNUTT/Views/Scenes/LectureDetailScene.swift @@ -91,6 +91,14 @@ struct LectureDetailScene: View { .onAppear { isMapViewExpanded = viewModel.shouldOpenLectureMapView() } + .onAppear { + Task { + if let evLecture = await viewModel.getEvLectureInfo(of: lecture) { + lecture.updateEvLecture(to: evLecture) + viewModel.reloadDetailWebView(detailId: evLecture.evLectureId) + } + } + } .onChange(of: isMapViewExpanded) { viewModel.setIsMapViewExpanded($0) } @@ -498,14 +506,6 @@ struct LectureDetailScene: View { DetailButton(text: "강의평") { showReviewWebView = true } - .onAppear { - Task { - if let evLecture = await viewModel.getEvLectureInfo(of: lecture) { - lecture.updateEvLecture(to: evLecture) - viewModel.reloadDetailWebView(detailId: evLecture.evLectureId) - } - } - } .sheet(isPresented: $showReviewWebView) { ReviewScene(viewModel: .init(container: viewModel.container), isMainWebView: false, detailId: lecture.evLecture?.evLectureId) .id(colorScheme)