From ae80673d5bc2009995776a516b254f7923645f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Junnos=20=EF=A3=BF?= Date: Mon, 11 Dec 2023 12:07:40 +0900 Subject: [PATCH 1/3] =?UTF-8?q?:bug:=20UserID=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presentation/HomeViewController.swift | 5 ++-- .../MapViewController+EventListener.swift | 23 +++++++++++++------ .../MSData/Repository/JourneyRepository.swift | 3 ++- .../MSData/Repository/UserRepository.swift | 23 +++++++++++++++++++ .../MSCoordinator/HomeCoordinator.swift | 8 +++---- iOS/MusicSpot/MusicSpot/SceneDelegate.swift | 12 ++++++++-- 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift b/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift index 7420dcd..ee5cee3 100644 --- a/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift +++ b/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift @@ -128,7 +128,7 @@ public final class HomeViewController: HomeBottomSheetViewController { self.viewModel.state.startedJourney .receive(on: DispatchQueue.main) .sink { [weak self] startedJourney in - self?.contentViewController.journeyDidStarted(startedJourney) + self?.contentViewController.journeyShouldStarted(startedJourney) } .store(in: &self.cancellables) @@ -140,6 +140,7 @@ public final class HomeViewController: HomeBottomSheetViewController { .store(in: &self.cancellables) self.viewModel.state.isRecording + .removeDuplicates() .receive(on: DispatchQueue.main) .sink { [weak self] isRecording in if isRecording { @@ -225,7 +226,7 @@ extension HomeViewController: RecordJourneyButtonViewDelegate { guard self.viewModel.state.isRecording.value == true else { return } self.viewModel.trigger(.backButtonDidTap) - self.contentViewController.journeyDidCancelled() + self.contentViewController.journeyShouldStopped() } public func spotButtonDidTap(_ button: MSRectButton) { diff --git a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift index ff6ad14..5c4c09d 100644 --- a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift +++ b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift @@ -9,6 +9,7 @@ import Foundation import MSData import MSDomain +import MSLogger // MARK: - NavigateMap @@ -26,17 +27,25 @@ extension MapViewController { extension MapViewController { - public func journeyDidStarted(_ startedJourney: RecordingJourney) { + public func journeyShouldStarted(_ startedJourney: RecordingJourney) { + guard let viewModel = self.viewModel as? NavigateMapViewModel else { + MSLogger.make(category: .home).error("여정이 시작되어야 하지만 이미 Map에서 RecordJourneyViewModel을 사용하고 있습니다.") + return + } + let userRepository = UserRepositoryImplementation() let journeyRepository = JourneyRepositoryImplementation() - let viewModel = RecordJourneyViewModel(startedJourney: startedJourney, - userRepository: userRepository, - journeyRepository: journeyRepository) - self.swapViewModel(to: viewModel) + let recordJourneyViewModel = RecordJourneyViewModel(startedJourney: startedJourney, + userRepository: userRepository, + journeyRepository: journeyRepository) + self.swapViewModel(to: recordJourneyViewModel) } - public func journeyDidCancelled() { - guard let viewModel = self.viewModel as? RecordJourneyViewModel else { return } + public func journeyShouldStopped() { + guard let viewModel = self.viewModel as? RecordJourneyViewModel else { + MSLogger.make(category: .home).error("여정이 종료되어야 하지만 이미 Map에서 NavigateMapViewModel을 사용하고 있습니다.") + return + } viewModel.trigger(.recordingDidCancelled) let journeyRepository = JourneyRepositoryImplementation() diff --git a/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift b/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift index 9d6b389..2a5c26e 100644 --- a/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift +++ b/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift @@ -133,9 +133,10 @@ public struct JourneyRepositoryImplementation: JourneyRepository { self.saveToLocal(value: recordingJourney.id) self.saveToLocal(value: recordingJourney.startTimestamp) - self.isRecording = true self.recordingJourneyID = recordingJourney.id + self.isRecording = true + #if DEBUG if let recordingJourneyID = self.recordingJourneyID { MSLogger.make(category: .userDefaults).debug("기록중인 여정 정보가 저장되었습니다: \(recordingJourneyID)") diff --git a/iOS/MSData/Sources/MSData/Repository/UserRepository.swift b/iOS/MSData/Sources/MSData/Repository/UserRepository.swift index cb7d6fc..24954a7 100644 --- a/iOS/MSData/Sources/MSData/Repository/UserRepository.swift +++ b/iOS/MSData/Sources/MSData/Repository/UserRepository.swift @@ -14,6 +14,7 @@ import MSNetworking public protocol UserRepository { func createUser() async -> Result + func storeUUID(_ userID: UUID) throws -> UUID func fetchUUID() -> UUID? } @@ -40,8 +41,14 @@ public struct UserRepositoryImplementation: UserRepository { let userID: UUID if let existingUserID = self.fetchUUID() { userID = existingUserID + #if DEBUG + MSLogger.make(category: .keychain).debug("Keychain에 유저가 존재해 해당 유저 ID를 사용합니다: \(userID)") + #endif } else { userID = UUID() + #if DEBUG + MSLogger.make(category: .keychain).debug("Keychain에 유저가 존재하지 않아 새로운 유저 ID를 사용합니다: \(userID)") + #endif } let requestDTO = UserRequestDTO(userID: userID) @@ -50,12 +57,28 @@ public struct UserRepositoryImplementation: UserRepository { let result = await self.networking.request(UserResponseDTO.self, router: router) switch result { case .success(let userResponse): + if let storedUserID = try? self.storeUUID(userID) { + return .success(storedUserID) + } + MSLogger.make(category: .keychain).warning("서버에 새로운 유저를 생성했지만, Keychain에 저장하지 못했습니다.") return .success(userResponse.userID) case .failure(let error): return .failure(error) } } + @discardableResult + public func storeUUID(_ userID: UUID) throws -> UUID { + let account = MSKeychainStorage.Accounts.userID.rawValue + + do { + try self.keychain.set(value: userID, account: account) + return userID + } catch { + throw MSKeychainStorage.KeychainError.creationError + } + } + /// UUID가 이미 키체인에 등록되어 있다면 가져옵니다. public func fetchUUID() -> UUID? { let account = MSKeychainStorage.Accounts.userID.rawValue diff --git a/iOS/MusicSpot/MusicSpot/MSCoordinator/HomeCoordinator.swift b/iOS/MusicSpot/MusicSpot/MSCoordinator/HomeCoordinator.swift index 97e90b1..14e5e8a 100644 --- a/iOS/MusicSpot/MusicSpot/MSCoordinator/HomeCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/MSCoordinator/HomeCoordinator.swift @@ -133,13 +133,13 @@ extension HomeCoordinator: HomeCoordinatorDelegate { } func popToHome(from coordinator: Coordinator, with endedJourney: Journey) { - guard let viewController = self.navigationController.viewControllers.first(where: { - $0 is HomeViewController - }) else { + let viewControllers = self.navigationController.viewControllers + guard let viewController = viewControllers.first(where: { $0 is HomeViewController }), + let homeViewController = viewController as? HomeViewController else { return } - self.navigationController.popToViewController(viewController, animated: true) + self.navigationController.popToViewController(homeViewController, animated: true) } } diff --git a/iOS/MusicSpot/MusicSpot/SceneDelegate.swift b/iOS/MusicSpot/MusicSpot/SceneDelegate.swift index 748633e..4d5ebd4 100644 --- a/iOS/MusicSpot/MusicSpot/SceneDelegate.swift +++ b/iOS/MusicSpot/MusicSpot/SceneDelegate.swift @@ -24,6 +24,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { var recordingJourneyID: String? @UserDefaultsWrapped(UserDefaultsKey.isFirstLaunch, defaultValue: false) var isFirstLaunch: Bool + @UserDefaultsWrapped(UserDefaultsKey.isRecording, defaultValue: false) + var isRecording: Bool + var keychain = MSKeychainStorage() #endif @@ -36,6 +39,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let window = UIWindow(windowScene: windowScene) defer { self.window = window } + MSLogger.make(category: .userDefaults).info("isFirstLaunch: \(self.isFirstLaunch.description)") + MSLogger.make(category: .userDefaults).info("isRecording: \(self.isRecording.description)") + MSLogger.make(category: .userDefaults).info("recordingJourneyID: \(self.recordingJourneyID ?? "No Recording")") + + #if DEBUG + self.prepareToDebug() + #endif MSFont.registerFonts() let musicSpotNavigationController = self.makeNavigationController() @@ -65,7 +75,6 @@ private extension SceneDelegate { // MARK: - Debug #if DEBUG - import MSKeychainStorage import MSLogger import MSUserDefaults @@ -83,5 +92,4 @@ private extension SceneDelegate { } } - #endif From 15f57b2cf9d51d761877a100ce65f27c3069182e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Junnos=20=EF=A3=BF?= Date: Mon, 11 Dec 2023 12:13:36 +0900 Subject: [PATCH 2/3] =?UTF-8?q?:bug:=20Spot=EC=9D=B4=20=EB=A1=9C=EC=BB=AC?= =?UTF-8?q?=EC=97=90=20=EC=A0=80=EC=9E=A5=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EA=B3=A0=20=EC=9E=88=EB=8D=98=20=ED=98=84=EC=83=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/MSData/Repository/SpotRepository.swift | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/iOS/MSData/Sources/MSData/Repository/SpotRepository.swift b/iOS/MSData/Sources/MSData/Repository/SpotRepository.swift index 0eec86e..336cb94 100644 --- a/iOS/MSData/Sources/MSData/Repository/SpotRepository.swift +++ b/iOS/MSData/Sources/MSData/Repository/SpotRepository.swift @@ -81,15 +81,5 @@ public struct SpotRepositoryImplementation: SpotRepository { return .failure(error) } } - - // MARK: - Persistable - - public func saveToLocal(value: Codable) { - - } - - public func loadJourneyFromLocal() -> RecordingJourney? { - return nil - } } From 0dd34926a40819e1b154fa7c98fc980454bc9c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Junnos=20=EF=A3=BF?= Date: Mon, 11 Dec 2023 12:36:12 +0900 Subject: [PATCH 3/3] =?UTF-8?q?:bug:=20DEBUG=20=EC=8A=A4=ED=82=B4=EC=97=90?= =?UTF-8?q?=EC=84=9C=EB=A7=8C=20MSLogger=EB=A5=BC=20import=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/MusicSpot/MusicSpot/SceneDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS/MusicSpot/MusicSpot/SceneDelegate.swift b/iOS/MusicSpot/MusicSpot/SceneDelegate.swift index 4d5ebd4..d1c0929 100644 --- a/iOS/MusicSpot/MusicSpot/SceneDelegate.swift +++ b/iOS/MusicSpot/MusicSpot/SceneDelegate.swift @@ -11,6 +11,7 @@ import JourneyList import MSConstants import MSData import MSDesignSystem +import MSLogger class SceneDelegate: UIResponder, UIWindowSceneDelegate { @@ -76,7 +77,6 @@ private extension SceneDelegate { #if DEBUG import MSKeychainStorage -import MSLogger import MSUserDefaults private extension SceneDelegate {