|
8 | 8 | import FirebaseAuth |
9 | 9 | import Combine |
10 | 10 | import FirebaseFirestore |
| 11 | +import FirebaseFunctions |
11 | 12 |
|
12 | 13 | final class PushNotificationService { |
| 14 | + private enum FunctionName: String { |
| 15 | + case requestPushNotificationDeletion |
| 16 | + case undoPushNotificationDeletion |
| 17 | + } |
| 18 | + |
13 | 19 | private let store = Firestore.firestore() |
| 20 | + private let functions = Functions.functions(region: "asia-northeast3") |
14 | 21 | private let logger = Logger(category: "PushNotificationService") |
15 | 22 |
|
16 | 23 | /// 푸시 알림 On/Off 설정 |
@@ -174,13 +181,24 @@ final class PushNotificationService { |
174 | 181 | /// 푸시 알림 기록 삭제 |
175 | 182 | func deleteNotification(_ notificationID: String) async throws { |
176 | 183 | do { |
177 | | - guard let uid = Auth.auth().currentUser?.uid else { throw AuthError.notAuthenticated } |
| 184 | + guard Auth.auth().currentUser?.uid != nil else { throw AuthError.notAuthenticated } |
178 | 185 |
|
179 | | - let docRef = store.collection("users/\(uid)/notifications").document(notificationID) |
| 186 | + let function = functions.httpsCallable(FunctionName.requestPushNotificationDeletion) |
| 187 | + _ = try await function.call(["notificationId": notificationID]) |
| 188 | + } catch { |
| 189 | + logger.error("Failed to request notification deletion", error: error) |
| 190 | + throw error |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + func undoDeleteNotification(_ notificationID: String) async throws { |
| 195 | + do { |
| 196 | + guard Auth.auth().currentUser?.uid != nil else { throw AuthError.notAuthenticated } |
180 | 197 |
|
181 | | - try await docRef.delete() |
| 198 | + let function = functions.httpsCallable(FunctionName.undoPushNotificationDeletion) |
| 199 | + _ = try await function.call(["notificationId": notificationID]) |
182 | 200 | } catch { |
183 | | - logger.error("Failed to delete notification", error: error) |
| 201 | + logger.error("Failed to undo notification deletion", error: error) |
184 | 202 | throw error |
185 | 203 | } |
186 | 204 | } |
|
0 commit comments