From 91a1ebde55121951d707247174eee4e02366f7ab Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:16 +0900 Subject: [PATCH 01/11] =?UTF-8?q?REFACTOR:=20=EC=9C=A0=EC=A0=80=20DTO?= =?UTF-8?q?=EC=9D=98=20=EC=9C=84=EC=B9=98=20=EA=B3=B5=EC=9C=A0=20=EB=B2=94?= =?UTF-8?q?=EC=9C=84=20=EB=B3=80=ED=99=98=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/Firebase/DTO/UserDTO.swift | 26 ++++++++++++------- .../Repository/FirestoreUserRepository.swift | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/WhereAreYou/WhereAreYou/Data/Firebase/DTO/UserDTO.swift b/WhereAreYou/WhereAreYou/Data/Firebase/DTO/UserDTO.swift index f4a3bf2..73e774d 100644 --- a/WhereAreYou/WhereAreYou/Data/Firebase/DTO/UserDTO.swift +++ b/WhereAreYou/WhereAreYou/Data/Firebase/DTO/UserDTO.swift @@ -39,23 +39,31 @@ struct UserDTO { } }() - let sharingScope: LocationSharingScope = { - switch locationSharingScope { - case "ALWAYS": return .always - case "NEVER": return .never - default: return .onlyDuringAppointment - } - }() - return User( id: id, nickname: nickname, profileImage: profileImage, defaultTransportMode: transportMode, - locationSharingScope: sharingScope, + locationSharingScope: Self.locationSharingScope(from: locationSharingScope), isNotificationEnabled: isNotificationEnabled, appointmentsNotification: appointmentsNotification ) } + static func value(from scope: LocationSharingScope) -> String { + switch scope { + case .always: return "ALWAYS" + case .onlyDuringAppointment: return "ONLY_DURING_APPOINTMENT" + case .never: return "NEVER" + } + } + + private static func locationSharingScope(from value: String?) -> LocationSharingScope { + switch value { + case "ALWAYS": return .always + case "NEVER": return .never + default: return .onlyDuringAppointment + } + } + } diff --git a/WhereAreYou/WhereAreYou/Data/Firebase/Repository/FirestoreUserRepository.swift b/WhereAreYou/WhereAreYou/Data/Firebase/Repository/FirestoreUserRepository.swift index 121da41..653a71b 100644 --- a/WhereAreYou/WhereAreYou/Data/Firebase/Repository/FirestoreUserRepository.swift +++ b/WhereAreYou/WhereAreYou/Data/Firebase/Repository/FirestoreUserRepository.swift @@ -38,7 +38,7 @@ final class FirestoreUserRepository: UserRepository { "nickname": nickname, "profileImage": "basic", "defaultTransportMode": "TRANSIT", - "locationSharingScope": "ONLY_DURING_APPOINTMENT", + "locationSharingScope": UserDTO.value(from: .onlyDuringAppointment), "isNotificationEnabled": true, "appointmentsNotification": [String: Bool](), "createdAt": FieldValue.serverTimestamp() From ba36a20a0ef524c7364a452779d4476c75c5b072 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:16 +0900 Subject: [PATCH 02/11] =?UTF-8?q?FEAT:=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=88=98=EC=A0=95=20=EC=A0=80=EC=9E=A5=EC=86=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/FirestoreUserRepository.swift | 31 +++++++++++++++++++ .../Domain/Repository/UserRepository.swift | 11 ++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/WhereAreYou/WhereAreYou/Data/Firebase/Repository/FirestoreUserRepository.swift b/WhereAreYou/WhereAreYou/Data/Firebase/Repository/FirestoreUserRepository.swift index 653a71b..2048ee1 100644 --- a/WhereAreYou/WhereAreYou/Data/Firebase/Repository/FirestoreUserRepository.swift +++ b/WhereAreYou/WhereAreYou/Data/Firebase/Repository/FirestoreUserRepository.swift @@ -106,6 +106,37 @@ final class FirestoreUserRepository: UserRepository { } } + func updateUser( + userID: String, + nickname: String?, + profileImage: String?, + locationSharingScope: LocationSharingScope?, + isNotificationEnabled: Bool? + ) async throws -> User { + var fields: [String: Any] = [:] + if let nickname { + fields["nickname"] = nickname + } + if let profileImage { + fields["profileImage"] = profileImage + } + if let locationSharingScope { + fields["locationSharingScope"] = UserDTO.value(from: locationSharingScope) + } + if let isNotificationEnabled { + fields["isNotificationEnabled"] = isNotificationEnabled + } + + if !fields.isEmpty { + do { + try await db.collection("users").document(userID).updateData(fields) + } catch { + throw FirebaseErrorMapper.map(error) + } + } + return try await fetchUser(userID: userID) + } + private func fetchUsers(chunk: [String]) async throws -> [String: User] { let snapshot = try await db.collection("users") .whereField(FieldPath.documentID(), in: chunk) diff --git a/WhereAreYou/WhereAreYou/Domain/Repository/UserRepository.swift b/WhereAreYou/WhereAreYou/Domain/Repository/UserRepository.swift index b4e9e01..487504e 100644 --- a/WhereAreYou/WhereAreYou/Domain/Repository/UserRepository.swift +++ b/WhereAreYou/WhereAreYou/Domain/Repository/UserRepository.swift @@ -7,7 +7,7 @@ import Foundation -/// 사용자 저장소 — Firestore 유저 문서 생성, 조회 +/// 사용자 저장소 — Firestore 유저 문서 생성, 조회, 수정 protocol UserRepository { func createUserIfNeeded(userID: String, nickname: String) async throws -> User @@ -17,4 +17,13 @@ protocol UserRepository { /// 여러 사용자를 한 번에 조회해 ID별로 돌려준다. 없는 사용자는 결과에서 빠진다 func fetchUsers(userIDs: Set) async throws -> [String: User] + /// nil인 항목은 변경하지 않는다 + func updateUser( + userID: String, + nickname: String?, + profileImage: String?, + locationSharingScope: LocationSharingScope?, + isNotificationEnabled: Bool? + ) async throws -> User + } From ab30a2df1e3b91d5ea27b7e0130d44fa16856be2 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:17 +0900 Subject: [PATCH 03/11] =?UTF-8?q?FEAT:=20=EB=82=B4=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20=EC=9C=A0=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UseCase/User/FetchMyUserUseCase.swift | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 WhereAreYou/WhereAreYou/Domain/UseCase/User/FetchMyUserUseCase.swift diff --git a/WhereAreYou/WhereAreYou/Domain/UseCase/User/FetchMyUserUseCase.swift b/WhereAreYou/WhereAreYou/Domain/UseCase/User/FetchMyUserUseCase.swift new file mode 100644 index 0000000..d32e7fb --- /dev/null +++ b/WhereAreYou/WhereAreYou/Domain/UseCase/User/FetchMyUserUseCase.swift @@ -0,0 +1,28 @@ +// +// FetchMyUserUseCase.swift +// WhereAreYou +// +// Created by 이상유 on 2026-11-15. +// + +import Foundation + +/// 로그인한 내 유저 정보를 조회한다 — 로그인 상태가 아니면 AppError.notAuthenticated +final class FetchMyUserUseCase { + + private let authRepository: AuthRepository + private let userRepository: UserRepository + + init(authRepository: AuthRepository, userRepository: UserRepository) { + self.authRepository = authRepository + self.userRepository = userRepository + } + + func execute() async throws -> User { + guard let userID = authRepository.currentUserID else { + throw AppError.notAuthenticated + } + return try await userRepository.fetchUser(userID: userID) + } + +} From 1f62b5bb959843e478c69dbecf023bac084acd32 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:17 +0900 Subject: [PATCH 04/11] =?UTF-8?q?FEAT:=20=EB=82=B4=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=20=EC=9C=A0=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UseCase/User/UpdateMyUserUseCase.swift | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 WhereAreYou/WhereAreYou/Domain/UseCase/User/UpdateMyUserUseCase.swift diff --git a/WhereAreYou/WhereAreYou/Domain/UseCase/User/UpdateMyUserUseCase.swift b/WhereAreYou/WhereAreYou/Domain/UseCase/User/UpdateMyUserUseCase.swift new file mode 100644 index 0000000..72a6c86 --- /dev/null +++ b/WhereAreYou/WhereAreYou/Domain/UseCase/User/UpdateMyUserUseCase.swift @@ -0,0 +1,39 @@ +// +// UpdateMyUserUseCase.swift +// WhereAreYou +// +// Created by 이상유 on 2026-11-15. +// + +import Foundation + +/// 내 유저 정보(프로필·위치 공유 범위·전체 알림)를 수정하고 저장된 값을 돌려준다 — nil인 항목은 변경하지 않는다 +final class UpdateMyUserUseCase { + + private let authRepository: AuthRepository + private let userRepository: UserRepository + + init(authRepository: AuthRepository, userRepository: UserRepository) { + self.authRepository = authRepository + self.userRepository = userRepository + } + + func execute( + nickname: String? = nil, + profileImage: String? = nil, + locationSharingScope: LocationSharingScope? = nil, + isNotificationEnabled: Bool? = nil + ) async throws -> User { + guard let userID = authRepository.currentUserID else { + throw AppError.notAuthenticated + } + return try await userRepository.updateUser( + userID: userID, + nickname: nickname, + profileImage: profileImage, + locationSharingScope: locationSharingScope, + isNotificationEnabled: isNotificationEnabled + ) + } + +} From c308b3a747cc8c11ffd97c31bdb830724b85d003 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:17 +0900 Subject: [PATCH 05/11] =?UTF-8?q?FEAT:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=ED=91=9C=EC=8B=9C=20=EB=AA=A8=EB=8D=B8?= =?UTF-8?q?=EC=9D=98=20=EC=9C=A0=EC=A0=80=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EB=B3=80=ED=99=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PresentationModel/LocationSharingOption.swift | 8 ++++++++ .../PresentationModel/MyPageProfile.swift | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/WhereAreYou/WhereAreYou/Presentation/PresentationModel/LocationSharingOption.swift b/WhereAreYou/WhereAreYou/Presentation/PresentationModel/LocationSharingOption.swift index 59a363c..65085b1 100644 --- a/WhereAreYou/WhereAreYou/Presentation/PresentationModel/LocationSharingOption.swift +++ b/WhereAreYou/WhereAreYou/Presentation/PresentationModel/LocationSharingOption.swift @@ -23,4 +23,12 @@ enum LocationSharingOption: CaseIterable { } } + var scope: LocationSharingScope { + switch self { + case .always: return .always + case .onlyDuringAppointment: return .onlyDuringAppointment + case .never: return .never + } + } + } diff --git a/WhereAreYou/WhereAreYou/Presentation/PresentationModel/MyPageProfile.swift b/WhereAreYou/WhereAreYou/Presentation/PresentationModel/MyPageProfile.swift index af7476a..e085639 100644 --- a/WhereAreYou/WhereAreYou/Presentation/PresentationModel/MyPageProfile.swift +++ b/WhereAreYou/WhereAreYou/Presentation/PresentationModel/MyPageProfile.swift @@ -13,3 +13,14 @@ struct MyPageProfile { let locationSharingOption: LocationSharingOption let isNotificationEnabled: Bool } + +extension MyPageProfile { + + init(user: User) { + nickname = user.nickname + profileImageName = user.profileImage + locationSharingOption = LocationSharingOption(scope: user.locationSharingScope) + isNotificationEnabled = user.isNotificationEnabled + } + +} From 61bdb1ef1b283c78f58a587651ffa5883bd1e257 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:17 +0900 Subject: [PATCH 06/11] =?UTF-8?q?FEAT:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=82=B4=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=8B=A4=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ScreenFactory/ScreenFactory+MyPage.swift | 8 ++- .../MyPage/MyPageViewController.swift | 60 ++++++++++--------- .../Presentation/MyPage/MyPageViewModel.swift | 45 +++++++------- 3 files changed, 64 insertions(+), 49 deletions(-) diff --git a/WhereAreYou/WhereAreYou/Core/DI/Implementation/ScreenFactory/ScreenFactory+MyPage.swift b/WhereAreYou/WhereAreYou/Core/DI/Implementation/ScreenFactory/ScreenFactory+MyPage.swift index 8b7602e..25ce754 100644 --- a/WhereAreYou/WhereAreYou/Core/DI/Implementation/ScreenFactory/ScreenFactory+MyPage.swift +++ b/WhereAreYou/WhereAreYou/Core/DI/Implementation/ScreenFactory/ScreenFactory+MyPage.swift @@ -8,7 +8,13 @@ extension ScreenFactory { func makeMyPageViewController() -> MyPageViewController { + let authRepository = container.resolve(AuthRepository.self) + let userRepository = container.resolve(UserRepository.self) let viewModel = MyPageViewModel( + fetchMyUserUseCase: FetchMyUserUseCase( + authRepository: authRepository, + userRepository: userRepository + ), fetchMyAppointmentsUseCase: FetchMyAppointmentsUseCase( repository: container.resolve(AppointmentRepository.self) ), @@ -19,7 +25,7 @@ extension ScreenFactory { repository: container.resolve(LiveActivityPermissionRepository.self) ), signOutUseCase: SignOutUseCase( - authRepository: container.resolve(AuthRepository.self), + authRepository: authRepository, fcmInstallationIDRepository: container.resolve(FCMInstallationIDRepository.self) ) ) diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift index 6f275cd..44e2e11 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift @@ -58,16 +58,12 @@ final class MyPageViewController: UIViewController { imageView.widthAnchor.constraint(equalToConstant: 16).isActive = true return imageView }() - private lazy var profileRow: MyPageRow = { - let row = MyPageRow( - icon: nil, - title: "닉네임", - isCircularImage: true, - accessoryView: profileEditIcon - ) - row.setProfileIcon(viewModel.profile.profileImageName) - return row - }() + private lazy var profileRow = MyPageRow( + icon: nil, + title: "닉네임", + isCircularImage: true, + accessoryView: profileEditIcon + ) // MARK: - 위치 카드 @@ -108,6 +104,7 @@ final class MyPageViewController: UIViewController { super.viewDidLoad() view.backgroundColor = .systemBackground setUpLayout() + setUpStaticContent() setUpActions() bindViewModel() } @@ -115,7 +112,7 @@ final class MyPageViewController: UIViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) navigationController?.setNavigationBarHidden(true, animated: animated) - reloadContent() + viewModel.loadProfile() viewModel.loadAppointmentNotifications() } @@ -212,42 +209,44 @@ final class MyPageViewController: UIViewController { }, for: .valueChanged) } - private func reloadContent() { - let profile = viewModel.profile - - profileRow.value = profile.nickname - profileRow.setProfileIcon(profile.profileImageName) - locationSharingRow.value = profile.locationSharingOption.title - notificationSwitch.isOn = profile.isNotificationEnabled - notificationRow.value = profile.isNotificationEnabled ? "전체 알림 켜짐" : "전체 알림 꺼짐" - - updateAppointmentNotificationRow(items: viewModel.appointmentNotifications) - + private func setUpStaticContent() { appInfoRow.value = "버전 정보" signOutRow.value = "현재 계정에서 나가기" } + /// 내 정보를 아직 불러오지 못했으면 값을 비우고 스위치를 끈다 + private func updateProfileRows(_ profile: MyPageProfile?) { + profileRow.value = profile?.nickname + if let profile { + profileRow.setProfileIcon(profile.profileImageName) + } + locationSharingRow.value = profile?.locationSharingOption.title + notificationSwitch.isEnabled = profile != nil + notificationSwitch.setOn(profile?.isNotificationEnabled ?? false, animated: true) + notificationRow.value = profile.map { $0.isNotificationEnabled ? "전체 알림 켜짐" : "전체 알림 꺼짐" } + } + private func updateAppointmentNotificationRow(items: [AppointmentListItem]) { let enabledCount = items.filter { $0.isNotificationEnabled }.count appointmentNotificationRow.value = "\(enabledCount)개의 약속 알림 켜짐" } private func presentProfileEdit() { + guard let profile = viewModel.profile else { return } coordinator?.showProfileEdit( - nickname: viewModel.profile.nickname, - profileImageName: viewModel.profile.profileImageName + nickname: profile.nickname, + profileImageName: profile.profileImageName ) { [weak self] nickname, profileImageName in self?.viewModel.setProfile(nickname: nickname, profileImageName: profileImageName) - self?.reloadContent() } } private func presentLocationSharingSelection() { + guard let profile = viewModel.profile else { return } coordinator?.showLocationSharingSelection( - selectedOption: viewModel.profile.locationSharingOption + selectedOption: profile.locationSharingOption ) { [weak self] option in self?.viewModel.setLocationSharingOption(option) - self?.locationSharingRow.value = option.title } } @@ -256,6 +255,13 @@ final class MyPageViewController: UIViewController { } private func bindViewModel() { + viewModel.$profile + .receive(on: DispatchQueue.main) + .sink { [weak self] profile in + self?.updateProfileRows(profile) + } + .store(in: &cancellables) + viewModel.$appointmentNotifications .receive(on: DispatchQueue.main) .sink { [weak self] items in diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift index 7759b7e..01d980f 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift @@ -9,7 +9,7 @@ import Combine import Foundation // MARK: - 마이페이지 화면(탭)의 데이터 -// - profile: 프로필 카드에 표시할 사용자 정보 +// - profile: 프로필 카드·위치 공유·전체 알림에 표시할 내 유저 정보 // - appointmentNotifications: 약속별 알림 화면에서 쓸 약속 목록 // - locationPermissionState: 위치 권한 상태를 표시용 타입으로 변환해 발행 // (실제 CoreLocation 접근은 Data 계층이 담당하며, ObserveLocationPermissionUseCase를 통해 전달받음) @@ -18,26 +18,27 @@ import Foundation final class MyPageViewModel { - private(set) var profile: MyPageProfile + @Published private(set) var profile: MyPageProfile? @Published private(set) var appointmentNotifications: [AppointmentListItem] = [] @Published private(set) var locationPermissionState: LocationPermissionState @Published private(set) var liveActivityPermissionState: LiveActivityPermissionState @Published private(set) var signOutResult: Result? + private let fetchMyUserUseCase: FetchMyUserUseCase private let fetchMyAppointmentsUseCase: FetchMyAppointmentsUseCase private let observeLocationPermissionUseCase: ObserveLocationPermissionUseCase private let observeLiveActivityPermissionUseCase: ObserveLiveActivityPermissionUseCase private let signOutUseCase: SignOutUseCase init( - profile: MyPageProfile? = nil, + fetchMyUserUseCase: FetchMyUserUseCase, fetchMyAppointmentsUseCase: FetchMyAppointmentsUseCase, observeLocationPermissionUseCase: ObserveLocationPermissionUseCase, observeLiveActivityPermissionUseCase: ObserveLiveActivityPermissionUseCase, signOutUseCase: SignOutUseCase ) { - self.profile = profile ?? Self.makeDummyProfile() + self.fetchMyUserUseCase = fetchMyUserUseCase self.fetchMyAppointmentsUseCase = fetchMyAppointmentsUseCase self.observeLocationPermissionUseCase = observeLocationPermissionUseCase self.observeLiveActivityPermissionUseCase = observeLiveActivityPermissionUseCase @@ -66,39 +67,41 @@ final class MyPageViewModel { extension MyPageViewModel { + /// 실패해도 알럿 없이 이전 값을 유지한다 + func loadProfile() { + Task { @MainActor in + guard let user = try? await fetchMyUserUseCase.execute() else { return } + profile = MyPageProfile(user: user) + } + } + func setProfile(nickname: String, profileImageName: String) { + guard let current = profile else { return } profile = MyPageProfile( nickname: nickname, profileImageName: profileImageName, - locationSharingOption: profile.locationSharingOption, - isNotificationEnabled: profile.isNotificationEnabled + locationSharingOption: current.locationSharingOption, + isNotificationEnabled: current.isNotificationEnabled ) } func setNotificationEnabled(_ isEnabled: Bool) { + guard let current = profile else { return } profile = MyPageProfile( - nickname: profile.nickname, - profileImageName: profile.profileImageName, - locationSharingOption: profile.locationSharingOption, + nickname: current.nickname, + profileImageName: current.profileImageName, + locationSharingOption: current.locationSharingOption, isNotificationEnabled: isEnabled ) } func setLocationSharingOption(_ option: LocationSharingOption) { + guard let current = profile else { return } profile = MyPageProfile( - nickname: profile.nickname, - profileImageName: profile.profileImageName, + nickname: current.nickname, + profileImageName: current.profileImageName, locationSharingOption: option, - isNotificationEnabled: profile.isNotificationEnabled - ) - } - - private static func makeDummyProfile() -> MyPageProfile { - MyPageProfile( - nickname: "성훈", - profileImageName: "shark", - locationSharingOption: .onlyDuringAppointment, - isNotificationEnabled: true + isNotificationEnabled: current.isNotificationEnabled ) } From 5b274d06fa6ac9d6e258f6bd45c8830239fb5e2f Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:17 +0900 Subject: [PATCH 07/11] =?UTF-8?q?FEAT:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=82=B4=EC=9A=A9=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ScreenFactory/ScreenFactory+MyPage.swift | 4 + .../MyPage/MyPageViewController.swift | 25 ++++- .../Presentation/MyPage/MyPageViewModel.swift | 94 ++++++++++++++----- 3 files changed, 96 insertions(+), 27 deletions(-) diff --git a/WhereAreYou/WhereAreYou/Core/DI/Implementation/ScreenFactory/ScreenFactory+MyPage.swift b/WhereAreYou/WhereAreYou/Core/DI/Implementation/ScreenFactory/ScreenFactory+MyPage.swift index 25ce754..40ccc5b 100644 --- a/WhereAreYou/WhereAreYou/Core/DI/Implementation/ScreenFactory/ScreenFactory+MyPage.swift +++ b/WhereAreYou/WhereAreYou/Core/DI/Implementation/ScreenFactory/ScreenFactory+MyPage.swift @@ -15,6 +15,10 @@ extension ScreenFactory { authRepository: authRepository, userRepository: userRepository ), + updateMyUserUseCase: UpdateMyUserUseCase( + authRepository: authRepository, + userRepository: userRepository + ), fetchMyAppointmentsUseCase: FetchMyAppointmentsUseCase( repository: container.resolve(AppointmentRepository.self) ), diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift index 44e2e11..eb928b8 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift @@ -205,7 +205,7 @@ final class MyPageViewController: UIViewController { notificationSwitch.addAction(UIAction { [weak self] _ in guard let self else { return } - viewModel.setNotificationEnabled(notificationSwitch.isOn) + viewModel.saveNotificationEnabled(notificationSwitch.isOn) }, for: .valueChanged) } @@ -237,7 +237,7 @@ final class MyPageViewController: UIViewController { nickname: profile.nickname, profileImageName: profile.profileImageName ) { [weak self] nickname, profileImageName in - self?.viewModel.setProfile(nickname: nickname, profileImageName: profileImageName) + self?.viewModel.saveProfile(nickname: nickname, profileImageName: profileImageName) } } @@ -246,7 +246,7 @@ final class MyPageViewController: UIViewController { coordinator?.showLocationSharingSelection( selectedOption: profile.locationSharingOption ) { [weak self] option in - self?.viewModel.setLocationSharingOption(option) + self?.viewModel.saveLocationSharingOption(option) } } @@ -262,6 +262,14 @@ final class MyPageViewController: UIViewController { } .store(in: &cancellables) + viewModel.$profileSaveError + .compactMap { $0 } + .receive(on: DispatchQueue.main) + .sink { [weak self] error in + self?.showProfileSaveError(error) + } + .store(in: &cancellables) + viewModel.$appointmentNotifications .receive(on: DispatchQueue.main) .sink { [weak self] items in @@ -316,6 +324,17 @@ final class MyPageViewController: UIViewController { present(alert, animated: true) } + /// 위치 공유 설정 화면처럼 하위 화면이 떠 있는 동안 실패할 수 있어, 화면에 붙어 있는 내비게이션 컨트롤러에서 띄운다 + private func showProfileSaveError(_ error: Error) { + let alert = UIAlertController( + title: "저장 실패", + message: error.localizedDescription, + preferredStyle: .alert + ) + alert.addAction(UIAlertAction(title: "확인", style: .default)) + (navigationController ?? self).present(alert, animated: true) + } + private func presentAppointmentNotificationList() { coordinator?.showAppointmentNotificationList( fetchItems: { [weak self] in self?.viewModel.appointmentNotifications ?? [] }, diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift index 01d980f..14b348c 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift @@ -10,6 +10,7 @@ import Foundation // MARK: - 마이페이지 화면(탭)의 데이터 // - profile: 프로필 카드·위치 공유·전체 알림에 표시할 내 유저 정보 +// (수정은 화면에 먼저 반영하고, 저장에 실패하면 이전 값으로 되돌린 뒤 profileSaveError를 발행) // - appointmentNotifications: 약속별 알림 화면에서 쓸 약속 목록 // - locationPermissionState: 위치 권한 상태를 표시용 타입으로 변환해 발행 // (실제 CoreLocation 접근은 Data 계층이 담당하며, ObserveLocationPermissionUseCase를 통해 전달받음) @@ -19,6 +20,7 @@ import Foundation final class MyPageViewModel { @Published private(set) var profile: MyPageProfile? + @Published private(set) var profileSaveError: Error? @Published private(set) var appointmentNotifications: [AppointmentListItem] = [] @Published private(set) var locationPermissionState: LocationPermissionState @@ -26,19 +28,25 @@ final class MyPageViewModel { @Published private(set) var signOutResult: Result? private let fetchMyUserUseCase: FetchMyUserUseCase + private let updateMyUserUseCase: UpdateMyUserUseCase private let fetchMyAppointmentsUseCase: FetchMyAppointmentsUseCase private let observeLocationPermissionUseCase: ObserveLocationPermissionUseCase private let observeLiveActivityPermissionUseCase: ObserveLiveActivityPermissionUseCase private let signOutUseCase: SignOutUseCase + /// 저장 요청마다 올라가는 번호 — 늦게 도착한 이전 요청의 결과가 최신 값을 덮어쓰지 않게 한다 + private var latestProfileSaveID = 0 + init( fetchMyUserUseCase: FetchMyUserUseCase, + updateMyUserUseCase: UpdateMyUserUseCase, fetchMyAppointmentsUseCase: FetchMyAppointmentsUseCase, observeLocationPermissionUseCase: ObserveLocationPermissionUseCase, observeLiveActivityPermissionUseCase: ObserveLiveActivityPermissionUseCase, signOutUseCase: SignOutUseCase ) { self.fetchMyUserUseCase = fetchMyUserUseCase + self.updateMyUserUseCase = updateMyUserUseCase self.fetchMyAppointmentsUseCase = fetchMyAppointmentsUseCase self.observeLocationPermissionUseCase = observeLocationPermissionUseCase self.observeLiveActivityPermissionUseCase = observeLiveActivityPermissionUseCase @@ -75,34 +83,72 @@ extension MyPageViewModel { } } - func setProfile(nickname: String, profileImageName: String) { - guard let current = profile else { return } - profile = MyPageProfile( - nickname: nickname, - profileImageName: profileImageName, - locationSharingOption: current.locationSharingOption, - isNotificationEnabled: current.isNotificationEnabled - ) + func saveProfile(nickname: String, profileImageName: String) { + guard let current = profile, + nickname != current.nickname || profileImageName != current.profileImageName + else { return } + + save( + MyPageProfile( + nickname: nickname, + profileImageName: profileImageName, + locationSharingOption: current.locationSharingOption, + isNotificationEnabled: current.isNotificationEnabled + ) + ) { [updateMyUserUseCase] in + try await updateMyUserUseCase.execute(nickname: nickname, profileImage: profileImageName) + } } - func setNotificationEnabled(_ isEnabled: Bool) { - guard let current = profile else { return } - profile = MyPageProfile( - nickname: current.nickname, - profileImageName: current.profileImageName, - locationSharingOption: current.locationSharingOption, - isNotificationEnabled: isEnabled - ) + func saveNotificationEnabled(_ isEnabled: Bool) { + guard let current = profile, isEnabled != current.isNotificationEnabled else { return } + + save( + MyPageProfile( + nickname: current.nickname, + profileImageName: current.profileImageName, + locationSharingOption: current.locationSharingOption, + isNotificationEnabled: isEnabled + ) + ) { [updateMyUserUseCase] in + try await updateMyUserUseCase.execute(isNotificationEnabled: isEnabled) + } } - func setLocationSharingOption(_ option: LocationSharingOption) { - guard let current = profile else { return } - profile = MyPageProfile( - nickname: current.nickname, - profileImageName: current.profileImageName, - locationSharingOption: option, - isNotificationEnabled: current.isNotificationEnabled - ) + func saveLocationSharingOption(_ option: LocationSharingOption) { + guard let current = profile, option != current.locationSharingOption else { return } + + save( + MyPageProfile( + nickname: current.nickname, + profileImageName: current.profileImageName, + locationSharingOption: option, + isNotificationEnabled: current.isNotificationEnabled + ) + ) { [updateMyUserUseCase] in + try await updateMyUserUseCase.execute(locationSharingScope: option.scope) + } + } + + /// 바뀐 값을 먼저 화면에 반영하고 저장한다. 성공하면 저장된 값으로, 실패하면 이전 값으로 맞춘다 + private func save(_ newProfile: MyPageProfile, update: @escaping () async throws -> User) { + guard let previous = profile else { return } + + latestProfileSaveID += 1 + let saveID = latestProfileSaveID + profile = newProfile + + Task { @MainActor in + do { + let user = try await update() + guard saveID == latestProfileSaveID else { return } + profile = MyPageProfile(user: user) + } catch { + guard saveID == latestProfileSaveID else { return } + profile = previous + profileSaveError = error + } + } } } From b374859e8aab56725a0f9d25ce7ab16f792192dc Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:17 +0900 Subject: [PATCH 08/11] =?UTF-8?q?FIX:=20=EC=9C=84=EC=B9=98=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=20=EC=84=A4=EC=A0=95=20=EC=A0=80=EC=9E=A5=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=EC=8B=9C=20=EC=84=A4=EC=A0=95=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=20=EC=83=88=20=EA=B0=92=EC=9D=B4=20=EB=82=A8=EB=8A=94?= =?UTF-8?q?=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyPage/MyPageViewController.swift | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift index eb928b8..461ae23 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift @@ -266,7 +266,7 @@ final class MyPageViewController: UIViewController { .compactMap { $0 } .receive(on: DispatchQueue.main) .sink { [weak self] error in - self?.showProfileSaveError(error) + self?.handleProfileSaveError(error) } .store(in: &cancellables) @@ -324,7 +324,25 @@ final class MyPageViewController: UIViewController { present(alert, animated: true) } - /// 위치 공유 설정 화면처럼 하위 화면이 떠 있는 동안 실패할 수 있어, 화면에 붙어 있는 내비게이션 컨트롤러에서 띄운다 + /// 위치 공유 설정 화면에 있는 동안 실패하면 되돌아간 값을 볼 수 있게 마이페이지로 돌아온 뒤 알럿을 띄운다 + private func handleProfileSaveError(_ error: Error) { + guard let navigationController, + navigationController.topViewController is LocationSharingSelectionViewController + else { + showProfileSaveError(error) + return + } + + navigationController.popToViewController(self, animated: true) + if let transitionCoordinator = navigationController.transitionCoordinator { + transitionCoordinator.animate(alongsideTransition: nil) { [weak self] _ in + self?.showProfileSaveError(error) + } + } else { + showProfileSaveError(error) + } + } + private func showProfileSaveError(_ error: Error) { let alert = UIAlertController( title: "저장 실패", From 31ee5a57f94bfd64f899120185b60ae5082db533 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:17 +0900 Subject: [PATCH 09/11] =?UTF-8?q?DESIGN:=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A0=80=EC=9E=A5=20=EC=8B=A4=ED=8C=A8=20=EC=95=8C?= =?UTF-8?q?=EB=9F=BF=EC=9D=98=20=ED=95=AD=EB=AA=A9=EB=B3=84=C2=B7=EC=9B=90?= =?UTF-8?q?=EC=9D=B8=EB=B3=84=20=EC=95=88=EB=82=B4=20=EB=AC=B8=EA=B5=AC=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyPage/MyPageViewController.swift | 33 ++++++++------ .../Presentation/MyPage/MyPageViewModel.swift | 43 ++++++++++++++++--- 2 files changed, 56 insertions(+), 20 deletions(-) diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift index 461ae23..700233e 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift @@ -262,11 +262,11 @@ final class MyPageViewController: UIViewController { } .store(in: &cancellables) - viewModel.$profileSaveError + viewModel.$profileSaveFailure .compactMap { $0 } .receive(on: DispatchQueue.main) - .sink { [weak self] error in - self?.handleProfileSaveError(error) + .sink { [weak self] failure in + self?.handleProfileSaveFailure(failure) } .store(in: &cancellables) @@ -325,30 +325,37 @@ final class MyPageViewController: UIViewController { } /// 위치 공유 설정 화면에 있는 동안 실패하면 되돌아간 값을 볼 수 있게 마이페이지로 돌아온 뒤 알럿을 띄운다 - private func handleProfileSaveError(_ error: Error) { + private func handleProfileSaveFailure(_ failure: ProfileSaveFailure) { guard let navigationController, + failure.item == .locationSharing, navigationController.topViewController is LocationSharingSelectionViewController else { - showProfileSaveError(error) + showProfileSaveFailureAlert(failure) return } navigationController.popToViewController(self, animated: true) if let transitionCoordinator = navigationController.transitionCoordinator { transitionCoordinator.animate(alongsideTransition: nil) { [weak self] _ in - self?.showProfileSaveError(error) + self?.showProfileSaveFailureAlert(failure) } } else { - showProfileSaveError(error) + showProfileSaveFailureAlert(failure) } } - private func showProfileSaveError(_ error: Error) { - let alert = UIAlertController( - title: "저장 실패", - message: error.localizedDescription, - preferredStyle: .alert - ) + private func showProfileSaveFailureAlert(_ failure: ProfileSaveFailure) { + let title: String + switch failure.item { + case .profile: title = "프로필이 바뀌지 않았어요" + case .locationSharing: title = "위치 공유 설정이 바뀌지 않았어요" + case .notification: title = "알림 설정이 바뀌지 않았어요" + } + let message = failure.isNetworkError + ? "네트워크 연결을 확인한 뒤 다시 시도해 주세요." + : "잠시 후 다시 시도해 주세요." + + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "확인", style: .default)) (navigationController ?? self).present(alert, animated: true) } diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift index 14b348c..f078022 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift @@ -10,7 +10,7 @@ import Foundation // MARK: - 마이페이지 화면(탭)의 데이터 // - profile: 프로필 카드·위치 공유·전체 알림에 표시할 내 유저 정보 -// (수정은 화면에 먼저 반영하고, 저장에 실패하면 이전 값으로 되돌린 뒤 profileSaveError를 발행) +// (수정은 화면에 먼저 반영하고, 저장에 실패하면 이전 값으로 되돌린 뒤 profileSaveFailure를 발행) // - appointmentNotifications: 약속별 알림 화면에서 쓸 약속 목록 // - locationPermissionState: 위치 권한 상태를 표시용 타입으로 변환해 발행 // (실제 CoreLocation 접근은 Data 계층이 담당하며, ObserveLocationPermissionUseCase를 통해 전달받음) @@ -20,7 +20,7 @@ import Foundation final class MyPageViewModel { @Published private(set) var profile: MyPageProfile? - @Published private(set) var profileSaveError: Error? + @Published private(set) var profileSaveFailure: ProfileSaveFailure? @Published private(set) var appointmentNotifications: [AppointmentListItem] = [] @Published private(set) var locationPermissionState: LocationPermissionState @@ -94,7 +94,8 @@ extension MyPageViewModel { profileImageName: profileImageName, locationSharingOption: current.locationSharingOption, isNotificationEnabled: current.isNotificationEnabled - ) + ), + item: .profile ) { [updateMyUserUseCase] in try await updateMyUserUseCase.execute(nickname: nickname, profileImage: profileImageName) } @@ -109,7 +110,8 @@ extension MyPageViewModel { profileImageName: current.profileImageName, locationSharingOption: current.locationSharingOption, isNotificationEnabled: isEnabled - ) + ), + item: .notification ) { [updateMyUserUseCase] in try await updateMyUserUseCase.execute(isNotificationEnabled: isEnabled) } @@ -124,14 +126,19 @@ extension MyPageViewModel { profileImageName: current.profileImageName, locationSharingOption: option, isNotificationEnabled: current.isNotificationEnabled - ) + ), + item: .locationSharing ) { [updateMyUserUseCase] in try await updateMyUserUseCase.execute(locationSharingScope: option.scope) } } /// 바뀐 값을 먼저 화면에 반영하고 저장한다. 성공하면 저장된 값으로, 실패하면 이전 값으로 맞춘다 - private func save(_ newProfile: MyPageProfile, update: @escaping () async throws -> User) { + private func save( + _ newProfile: MyPageProfile, + item: ProfileSaveFailure.Item, + update: @escaping () async throws -> User + ) { guard let previous = profile else { return } latestProfileSaveID += 1 @@ -146,13 +153,35 @@ extension MyPageViewModel { } catch { guard saveID == latestProfileSaveID else { return } profile = previous - profileSaveError = error + let isNetworkError: Bool + if case AppError.network = error { + isNetworkError = true + } else { + isNetworkError = false + } + profileSaveFailure = ProfileSaveFailure(item: item, isNetworkError: isNetworkError) } } } } +// MARK: - 저장 실패 + +/// 저장에 실패한 항목과 원인 — 화면이 알럿 문구를 만드는 데 쓴다 +struct ProfileSaveFailure { + + enum Item { + case profile + case locationSharing + case notification + } + + let item: Item + let isNetworkError: Bool + +} + // MARK: - 약속별 알림 extension MyPageViewModel { From 78f5757de79ab4ceff19ecd831be0d6e28dbbcaf Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 00:15:17 +0900 Subject: [PATCH 10/11] =?UTF-8?q?FEAT:=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A0=80=EC=9E=A5=20=EC=8B=A4=ED=8C=A8=20=EC=95=8C?= =?UTF-8?q?=EB=9F=BF=EC=97=90=20=EB=8B=A4=EC=8B=9C=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyPage/MyPageViewController.swift | 7 ++++++- .../Presentation/MyPage/MyPageViewModel.swift | 15 ++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift index 700233e..af76d81 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewController.swift @@ -356,7 +356,12 @@ final class MyPageViewController: UIViewController { : "잠시 후 다시 시도해 주세요." let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) - alert.addAction(UIAlertAction(title: "확인", style: .default)) + alert.addAction(UIAlertAction(title: "취소", style: .cancel)) + let retryAction = UIAlertAction(title: "다시 시도", style: .default) { _ in + failure.retry() + } + alert.addAction(retryAction) + alert.preferredAction = retryAction (navigationController ?? self).present(alert, animated: true) } diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift index f078022..4b39bb1 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift @@ -95,7 +95,8 @@ extension MyPageViewModel { locationSharingOption: current.locationSharingOption, isNotificationEnabled: current.isNotificationEnabled ), - item: .profile + item: .profile, + retry: { [weak self] in self?.saveProfile(nickname: nickname, profileImageName: profileImageName) } ) { [updateMyUserUseCase] in try await updateMyUserUseCase.execute(nickname: nickname, profileImage: profileImageName) } @@ -111,7 +112,8 @@ extension MyPageViewModel { locationSharingOption: current.locationSharingOption, isNotificationEnabled: isEnabled ), - item: .notification + item: .notification, + retry: { [weak self] in self?.saveNotificationEnabled(isEnabled) } ) { [updateMyUserUseCase] in try await updateMyUserUseCase.execute(isNotificationEnabled: isEnabled) } @@ -127,7 +129,8 @@ extension MyPageViewModel { locationSharingOption: option, isNotificationEnabled: current.isNotificationEnabled ), - item: .locationSharing + item: .locationSharing, + retry: { [weak self] in self?.saveLocationSharingOption(option) } ) { [updateMyUserUseCase] in try await updateMyUserUseCase.execute(locationSharingScope: option.scope) } @@ -137,6 +140,7 @@ extension MyPageViewModel { private func save( _ newProfile: MyPageProfile, item: ProfileSaveFailure.Item, + retry: @escaping () -> Void, update: @escaping () async throws -> User ) { guard let previous = profile else { return } @@ -159,7 +163,7 @@ extension MyPageViewModel { } else { isNetworkError = false } - profileSaveFailure = ProfileSaveFailure(item: item, isNetworkError: isNetworkError) + profileSaveFailure = ProfileSaveFailure(item: item, isNetworkError: isNetworkError, retry: retry) } } } @@ -168,7 +172,7 @@ extension MyPageViewModel { // MARK: - 저장 실패 -/// 저장에 실패한 항목과 원인 — 화면이 알럿 문구를 만드는 데 쓴다 +/// 저장에 실패한 항목과 원인, 같은 값으로 다시 저장하는 동작 — 화면이 알럿 문구와 다시 시도 버튼을 만드는 데 쓴다 struct ProfileSaveFailure { enum Item { @@ -179,6 +183,7 @@ struct ProfileSaveFailure { let item: Item let isNetworkError: Bool + let retry: () -> Void } From 1051120b7f450f8b2cfce56a8792e7508487950d Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Mon, 16 Nov 2026 15:55:29 +0900 Subject: [PATCH 11/11] =?UTF-8?q?REFACTOR:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20=ED=81=B4=EB=A1=9C=EC=A0=80=EC=9D=98=20?= =?UTF-8?q?=EC=9C=A0=EC=8A=A4=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B0=B8?= =?UTF-8?q?=EC=A1=B0=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presentation/MyPage/MyPageViewModel.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift index 4b39bb1..755c250 100644 --- a/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift +++ b/WhereAreYou/WhereAreYou/Presentation/MyPage/MyPageViewModel.swift @@ -97,8 +97,8 @@ extension MyPageViewModel { ), item: .profile, retry: { [weak self] in self?.saveProfile(nickname: nickname, profileImageName: profileImageName) } - ) { [updateMyUserUseCase] in - try await updateMyUserUseCase.execute(nickname: nickname, profileImage: profileImageName) + ) { + try await self.updateMyUserUseCase.execute(nickname: nickname, profileImage: profileImageName) } } @@ -114,8 +114,8 @@ extension MyPageViewModel { ), item: .notification, retry: { [weak self] in self?.saveNotificationEnabled(isEnabled) } - ) { [updateMyUserUseCase] in - try await updateMyUserUseCase.execute(isNotificationEnabled: isEnabled) + ) { + try await self.updateMyUserUseCase.execute(isNotificationEnabled: isEnabled) } } @@ -131,8 +131,8 @@ extension MyPageViewModel { ), item: .locationSharing, retry: { [weak self] in self?.saveLocationSharingOption(option) } - ) { [updateMyUserUseCase] in - try await updateMyUserUseCase.execute(locationSharingScope: option.scope) + ) { + try await self.updateMyUserUseCase.execute(locationSharingScope: option.scope) } }