Skip to content

Commit

Permalink
🐛 여정 취소 네트워킹이 실패한 경우에도 동작할 수 있도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftyJunnos committed Jan 10, 2024
1 parent a0b8013 commit 8f04848
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ public final class HomeViewController: HomeBottomSheetViewController {

self.viewModel.state.journeyDidCancelled
.receive(on: DispatchQueue.main)
.sink { [weak self] cancelledJourney in
.sink(receiveCompletion: { [weak self] completion in
if case .failure = completion {
self?.contentViewController.clearOverlays()
self?.contentViewController.recordingDidStop()
}
}, receiveValue: { [weak self] cancelledJourney in
self?.contentViewController.clearOverlays()
self?.contentViewController.recordingDidStop(cancelledJourney)
}
})
.store(in: &self.cancellables)

self.viewModel.state.visibleJourneys
Expand Down Expand Up @@ -196,7 +201,7 @@ public final class HomeViewController: HomeBottomSheetViewController {

private func updateButtonMode(isRecording: Bool) {
UIView.transition(with: self.view,
duration: 0.5,
duration: 0.34,
options: .transitionCrossDissolve,
animations: { [weak self] in
self?.startButton.isHidden = isRecording
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class HomeViewModel {
// Passthrough
public var journeyDidStarted = PassthroughSubject<RecordingJourney, Never>()
public var journeyDidResumed = PassthroughSubject<RecordingJourney, Never>()
public var journeyDidCancelled = PassthroughSubject<RecordingJourney, Never>()
public var journeyDidCancelled = PassthroughSubject<RecordingJourney, Error>()
public var visibleJourneys = PassthroughSubject<[Journey], Never>()

// CurrentValue
Expand Down Expand Up @@ -181,6 +181,7 @@ private extension HomeViewModel {
self.state.journeyDidCancelled.send(deletedJourney)
case .failure(let error):
MSLogger.make(category: .home).error("\(error)")
self.state.journeyDidCancelled.send(completion: .failure(error))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension MapViewController {
#endif
}

public func recordingDidStop(_ stoppedJourney: RecordingJourney) {
public func recordingDidStop(_ stoppedJourney: RecordingJourney? = nil) {
guard self.viewModel is RecordJourneyViewModel else {
MSLogger.make(category: .home).error("여정이 종료되어야 하지만 이미 Map에서 NavigateMapViewModel을 사용하고 있습니다.")
return
Expand All @@ -85,7 +85,9 @@ extension MapViewController {
self.locationManager.allowsBackgroundLocationUpdates = false

#if DEBUG
MSLogger.make(category: .home).debug("여정 기록이 종료되었습니다: \(stoppedJourney)")
if let stoppedJourney {
MSLogger.make(category: .home).debug("여정 기록이 종료되었습니다: \(stoppedJourney)")
}
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,16 @@ public struct JourneyRepositoryImplementation: JourneyRepository {

public mutating func deleteJourney(_ recordingJourney: RecordingJourney,
userID: UUID) async -> Result<RecordingJourney, Error> {
defer { try? self.recordingJourney.finish() }

let requestDTO = DeleteJourneyRequestDTO(userID: userID, journeyID: recordingJourney.id)
let router = JourneyRouter.deleteJourney(dto: requestDTO)
let result = await self.networking.request(DeleteJourneyResponseDTO.self, router: router)

switch result {
case .success(let responseDTO):
do {
try self.recordingJourney.finish()
let deletedJourney = responseDTO.toDomain()
return .success(deletedJourney)
} catch {
return .failure(error)
}
let deletedJourney = responseDTO.toDomain()
return .success(deletedJourney)
case .failure(let error):
return .failure(error)
}
Expand Down

0 comments on commit 8f04848

Please sign in to comment.