From ba923506f34f8421450d07535ac3ad00e9fc9d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Junnos=20=EF=A3=BF?= Date: Mon, 11 Dec 2023 10:17:06 +0900 Subject: [PATCH 1/3] =?UTF-8?q?:bug:=20=EC=97=AC=EC=A0=95=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=ED=97=A4=EB=8D=94=20=ED=84=B0=EC=B9=98=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=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 --- .../NavigateMap/Presentation/Common/MapViewController.swift | 2 ++ .../JourneyList/Presentation/VIew/MSCollectionView.swift | 5 ++++- ...dSpotResponseDTO.swift => RecordJourneyResponseDTO.swift} | 4 ++-- iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) rename iOS/MSData/Sources/MSData/DTO/Response/Journey/{RecordSpotResponseDTO.swift => RecordJourneyResponseDTO.swift} (77%) diff --git a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController.swift b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController.swift index a6c6b0f..ccdb759 100644 --- a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController.swift +++ b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController.swift @@ -313,7 +313,9 @@ extension MapViewController: CLLocationManagerDelegate { let coordinate2D = CLLocationCoordinate2D(latitude: newCurrentLocation.coordinate.latitude, longitude: newCurrentLocation.coordinate.longitude) + recordJourneyViewModel.trigger(.locationDidUpdated(coordinate2D)) + recordJourneyViewModel.trigger(.locationsShouldRecorded([coordinate2D])) } private func handleAuthorizationChange(_ manager: CLLocationManager) { diff --git a/iOS/Features/JourneyList/Sources/JourneyList/Presentation/VIew/MSCollectionView.swift b/iOS/Features/JourneyList/Sources/JourneyList/Presentation/VIew/MSCollectionView.swift index f3dbe88..20b5798 100644 --- a/iOS/Features/JourneyList/Sources/JourneyList/Presentation/VIew/MSCollectionView.swift +++ b/iOS/Features/JourneyList/Sources/JourneyList/Presentation/VIew/MSCollectionView.swift @@ -11,9 +11,12 @@ final class MSCollectionView: UICollectionView { override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { // Cell + let headers = self.visibleSupplementaryViews(ofKind: UICollectionView.elementKindSectionHeader) let cells = self.visibleCells for cell in cells where cell.frame.contains(point) { - return super.hitTest(point, with: event) + for header in headers where !header.frame.contains(point) { + return super.hitTest(point, with: event) + } } return nil diff --git a/iOS/MSData/Sources/MSData/DTO/Response/Journey/RecordSpotResponseDTO.swift b/iOS/MSData/Sources/MSData/DTO/Response/Journey/RecordJourneyResponseDTO.swift similarity index 77% rename from iOS/MSData/Sources/MSData/DTO/Response/Journey/RecordSpotResponseDTO.swift rename to iOS/MSData/Sources/MSData/DTO/Response/Journey/RecordJourneyResponseDTO.swift index 359b2a4..00de500 100644 --- a/iOS/MSData/Sources/MSData/DTO/Response/Journey/RecordSpotResponseDTO.swift +++ b/iOS/MSData/Sources/MSData/DTO/Response/Journey/RecordJourneyResponseDTO.swift @@ -1,5 +1,5 @@ // -// RecordSpotResponseDTO.swift +// RecordJourneyResponseDTO.swift // MSData // // Created by 이창준 on 2023.12.06. @@ -7,7 +7,7 @@ import Foundation -public struct RecordSpotResponseDTO: Decodable { +public struct RecordJourneyResponseDTO: Decodable { // MARK: - Properties diff --git a/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift b/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift index 9d9d604..9d6b389 100644 --- a/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift +++ b/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift @@ -156,11 +156,11 @@ public struct JourneyRepositoryImplementation: JourneyRepository { let coordinatesDTO = coordinates.map { CoordinateDTO($0) } let requestDTO = RecordCoordinateRequestDTO(journeyID: journeyID, coordinates: coordinatesDTO) let router = JourneyRouter.recordCoordinate(dto: requestDTO) - let result = await self.networking.request(RecordCoordinateRequestDTO.self, router: router) + let result = await self.networking.request(RecordJourneyResponseDTO.self, router: router) switch result { case .success(let responseDTO): let coordinates = responseDTO.coordinates.map { $0.toDomain() } - let recordingJourney = RecordingJourney(id: responseDTO.journeyID, + let recordingJourney = RecordingJourney(id: journeyID, startTimestamp: Date(), spots: [], coordinates: coordinates) From 2f043beea8d4514ab68271d4d7292c2e08a4f965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Junnos=20=EF=A3=BF?= Date: Mon, 11 Dec 2023 10:41:28 +0900 Subject: [PATCH 2/3] =?UTF-8?q?:art:=20DEBUG=20=EC=8A=A4=ED=82=B4=20?= =?UTF-8?q?=EC=95=B1=20=EC=B4=88=EA=B8=B0=ED=99=94=20SceneDelegate?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/Presentation/HomeViewModel.swift | 4 --- iOS/MusicSpot/MusicSpot/SceneDelegate.swift | 34 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift b/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift index 559795b..632f38e 100644 --- a/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift +++ b/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift @@ -68,10 +68,6 @@ public final class HomeViewModel { func trigger(_ action: Action) { switch action { case .viewNeedsLoaded: -// #if DEBUG -// self.isFirstLaunch = true -// try? self.keychain.deleteAll() -// #endif let firstLaunchMessage = self.isFirstLaunch ? "앱이 처음 실행되었습니다." : "앱 첫 실행이 아닙니다." MSLogger.make(category: .userDefaults).log("\(firstLaunchMessage)") diff --git a/iOS/MusicSpot/MusicSpot/SceneDelegate.swift b/iOS/MusicSpot/MusicSpot/SceneDelegate.swift index 42e8d6d..748633e 100644 --- a/iOS/MusicSpot/MusicSpot/SceneDelegate.swift +++ b/iOS/MusicSpot/MusicSpot/SceneDelegate.swift @@ -8,6 +8,7 @@ import UIKit import JourneyList +import MSConstants import MSData import MSDesignSystem @@ -18,6 +19,14 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? private var appCoordinator: Coordinator! + #if DEBUG + @UserDefaultsWrapped(UserDefaultsKey.recordingJourneyID, defaultValue: nil) + var recordingJourneyID: String? + @UserDefaultsWrapped(UserDefaultsKey.isFirstLaunch, defaultValue: false) + var isFirstLaunch: Bool + var keychain = MSKeychainStorage() + #endif + // MARK: - Functions func scene(_ scene: UIScene, @@ -51,3 +60,28 @@ private extension SceneDelegate { } } + + +// MARK: - Debug + +#if DEBUG + +import MSKeychainStorage +import MSLogger +import MSUserDefaults + +private extension SceneDelegate { + + func prepareToDebug() { + self.isFirstLaunch = true + self.recordingJourneyID = nil + do { + try self.keychain.deleteAll() + } catch { + MSLogger.make(category: .keychain).error("키체인 초기화 실패") + } + } + +} + +#endif From a3e58d7a10b911539ba9c75cb9d6dc13be661ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Junnos=20=EF=A3=BF?= Date: Mon, 11 Dec 2023 10:47:23 +0900 Subject: [PATCH 3/3] =?UTF-8?q?:art:=20UserID=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/Presentation/HomeViewModel.swift | 18 ++++++------- .../RecordJourneyViewModel.swift | 3 ++- .../MSKeychainStorage/MSKeychainStorage.swift | 2 +- .../MSData/Repository/UserRepository.swift | 26 ++++++++++++------- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift b/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift index 632f38e..79a6a1d 100644 --- a/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift +++ b/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift @@ -68,12 +68,12 @@ public final class HomeViewModel { func trigger(_ action: Action) { switch action { case .viewNeedsLoaded: + #if DEBUG let firstLaunchMessage = self.isFirstLaunch ? "앱이 처음 실행되었습니다." : "앱 첫 실행이 아닙니다." - MSLogger.make(category: .userDefaults).log("\(firstLaunchMessage)") + MSLogger.make(category: .userDefaults).debug("\(firstLaunchMessage)") + #endif - if self.isFirstLaunch { - self.createNewUser() - } + self.createNewUserWhenFirstLaunch() case .viewNeedsReloaded: let isRecording = self.journeyRepository.fetchIsRecording() self.state.isRecording.send(isRecording) @@ -99,7 +99,7 @@ public final class HomeViewModel { private extension HomeViewModel { - func createNewUser() { + func createNewUserWhenFirstLaunch() { guard self.isFirstLaunch else { return } Task { @@ -121,10 +121,8 @@ private extension HomeViewModel { self.state.isStartButtonLoading.send(true) defer { self.state.isStartButtonLoading.send(false) } - let userID = try self.userRepository.fetchUUID() - #if DEBUG - MSLogger.make(category: .home).debug("유저 ID 조회 성공: \(userID)") - #endif + guard let userID = self.userRepository.fetchUUID() else { return } + let result = await self.journeyRepository.startJourney(at: coordinate, userID: userID) switch result { case .success(let recordingJourney): @@ -137,7 +135,7 @@ private extension HomeViewModel { } func fetchJourneys(minCoordinate: Coordinate, maxCoordinate: Coordinate) { - guard let userID = try? self.userRepository.fetchUUID() else { return } + guard let userID = self.userRepository.fetchUUID() else { return } Task { let result = await self.journeyRepository.fetchJourneyList(userID: userID, diff --git a/iOS/Features/Home/Sources/NavigateMap/Presentation/RecordJourney/RecordJourneyViewModel.swift b/iOS/Features/Home/Sources/NavigateMap/Presentation/RecordJourney/RecordJourneyViewModel.swift index 54d5ebc..1d4e0f7 100644 --- a/iOS/Features/Home/Sources/NavigateMap/Presentation/RecordJourney/RecordJourneyViewModel.swift +++ b/iOS/Features/Home/Sources/NavigateMap/Presentation/RecordJourney/RecordJourneyViewModel.swift @@ -73,7 +73,8 @@ public final class RecordJourneyViewModel: MapViewModel { } case .recordingDidCancelled: Task { - let userID = try self.userRepository.fetchUUID() + guard let userID = self.userRepository.fetchUUID() else { return } + let recordingJourney = self.state.recordingJourney.value let result = await self.journeyRepository.deleteJourney(recordingJourney, userID: userID) switch result { diff --git a/iOS/MSCoreKit/Sources/MSKeychainStorage/MSKeychainStorage.swift b/iOS/MSCoreKit/Sources/MSKeychainStorage/MSKeychainStorage.swift index 70eda35..619c1fb 100644 --- a/iOS/MSCoreKit/Sources/MSKeychainStorage/MSKeychainStorage.swift +++ b/iOS/MSCoreKit/Sources/MSKeychainStorage/MSKeychainStorage.swift @@ -68,7 +68,7 @@ public struct MSKeychainStorage { /// Keychain에 저장된 모든 데이터를 삭제합니다. public func deleteAll() throws { - for account in Accounts.allCases { + for account in Accounts.allCases where try self.exists(account: account.rawValue) { try self.delete(account: account.rawValue) } } diff --git a/iOS/MSData/Sources/MSData/Repository/UserRepository.swift b/iOS/MSData/Sources/MSData/Repository/UserRepository.swift index eea4802..cb7d6fc 100644 --- a/iOS/MSData/Sources/MSData/Repository/UserRepository.swift +++ b/iOS/MSData/Sources/MSData/Repository/UserRepository.swift @@ -8,12 +8,13 @@ import Foundation import MSKeychainStorage +import MSLogger import MSNetworking public protocol UserRepository { func createUser() async -> Result - func fetchUUID() throws -> UUID + func fetchUUID() -> UUID? } @@ -35,8 +36,12 @@ public struct UserRepositoryImplementation: UserRepository { // MARK: - Functions public func createUser() async -> Result { - guard let userID = try? self.fetchUUID() else { - return .failure(MSKeychainStorage.KeychainError.transactionError) + // Keychain에 UserID가 저장되어 있는 지 확인하고 아니라면 새로 생성 + let userID: UUID + if let existingUserID = self.fetchUUID() { + userID = existingUserID + } else { + userID = UUID() } let requestDTO = UserRequestDTO(userID: userID) @@ -52,16 +57,17 @@ public struct UserRepositoryImplementation: UserRepository { } /// UUID가 이미 키체인에 등록되어 있다면 가져옵니다. - /// 그렇지 않다면 새로 생성하고, 키체인에 등록합니다. - public func fetchUUID() throws -> UUID { + public func fetchUUID() -> UUID? { let account = MSKeychainStorage.Accounts.userID.rawValue - if let userID = try? self.keychain.get(UUID.self, account: account) { - return userID + guard let userID = try? self.keychain.get(UUID.self, account: account) else { + MSLogger.make(category: .keychain).error("Keychain에서 UserID를 조회하는 것에 실패했습니다.") + return nil } - let newUserID = UUID() - try self.keychain.set(value: newUserID, account: account) - return newUserID + #if DEBUG + MSLogger.make(category: .keychain).debug("Keychain에서 UserID를 조회했습니다: \(userID)") + #endif + return userID } }