|
| 1 | +// |
| 2 | +// PushNotificationMapping.swift |
| 3 | +// DevLog |
| 4 | +// |
| 5 | +// Created by 최윤진 on 2/27/26. |
| 6 | +// |
| 7 | + |
| 8 | +import FirebaseFirestore |
| 9 | + |
| 10 | +extension PushNotificationResponse { |
| 11 | + func toDomain() throws -> PushNotification { |
| 12 | + guard let id = self.id else { |
| 13 | + throw DataError.invalidData("PushNotificationResponse.id is nil") |
| 14 | + } |
| 15 | + guard let todoKind = TodoKind(rawValue: self.todoKind) else { |
| 16 | + throw DataError.invalidData("PushNotificationResponse.todoKind is invalid: \(self.todoKind)") |
| 17 | + } |
| 18 | + |
| 19 | + return PushNotification( |
| 20 | + id: id, |
| 21 | + title: self.title, |
| 22 | + body: self.body, |
| 23 | + receivedAt: self.receivedAt.dateValue(), |
| 24 | + isRead: self.isRead, |
| 25 | + todoID: self.todoID, |
| 26 | + todoKind: todoKind |
| 27 | + ) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +extension PushNotificationCursorDTO { |
| 32 | + func toDomain() -> PushNotificationCursor { |
| 33 | + PushNotificationCursor( |
| 34 | + receivedAt: self.receivedAt.dateValue(), |
| 35 | + documentID: self.documentID |
| 36 | + ) |
| 37 | + } |
| 38 | + |
| 39 | + static func fromDomain(_ cursor: PushNotificationCursor) -> Self { |
| 40 | + PushNotificationCursorDTO( |
| 41 | + receivedAt: Timestamp(date: cursor.receivedAt), |
| 42 | + documentID: cursor.documentID |
| 43 | + ) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +extension PushNotificationPageResponse { |
| 48 | + func toDomain() throws -> PushNotificationPage { |
| 49 | + let items = try self.items.map { try $0.toDomain() } |
| 50 | + let nextCursor = self.nextCursor?.toDomain() |
| 51 | + return PushNotificationPage(items: items, nextCursor: nextCursor) |
| 52 | + } |
| 53 | +} |
0 commit comments