Skip to content

Commit b7bc425

Browse files
committed
refactor: DTO에서 Firestore 의존성을 제거 후 변환 형태를 서비스 레이어에서 담당하도록 수정
1 parent 9afa210 commit b7bc425

14 files changed

Lines changed: 120 additions & 81 deletions

DevLog/Data/DTO/PushNotificationCursorDTO.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// Created by 최윤진 on 2/27/26.
66
//
77

8-
import FirebaseFirestore
8+
import Foundation
99

1010
struct PushNotificationCursorDTO {
11-
let receivedAt: Timestamp
11+
let receivedAt: Date
1212
let documentID: String
1313
}

DevLog/Data/DTO/PushNotificationResponse.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// Created by 최윤진 on 2/10/26.
66
//
77

8-
import FirebaseFirestore
8+
import Foundation
99

10-
struct PushNotificationResponse: Decodable {
11-
@DocumentID var id: String?
10+
struct PushNotificationResponse {
11+
let id: String?
1212
let title: String
1313
let body: String
14-
let receivedAt: Timestamp
14+
let receivedAt: Date
1515
let isRead: Bool
1616
let todoID: String
1717
let todoKind: String

DevLog/Data/DTO/TodoCursorDTO.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// Created by opfic on 2/21/26.
66
//
77

8-
import FirebaseFirestore
8+
import Foundation
99

1010
struct TodoCursorDTO {
11-
let createdAt: Timestamp
11+
let createdAt: Date
1212
let documentID: String
1313
}

DevLog/Data/DTO/TodoDTO.swift

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
import Foundation
9-
import FirebaseFirestore
109

1110
struct TodoRequest: Dictionaryable {
1211
let id: String
@@ -23,8 +22,8 @@ struct TodoRequest: Dictionaryable {
2322

2423
}
2524

26-
struct TodoResponse: Decodable {
27-
@DocumentID var id: String?
25+
struct TodoResponse {
26+
let id: String?
2827
let isPinned: Bool
2928
let isCompleted: Bool
3029
let isChecked: Bool
@@ -35,45 +34,4 @@ struct TodoResponse: Decodable {
3534
let dueDate: Date?
3635
let tags: [String]
3736
let kind: String
38-
39-
init?(from snapshot: QueryDocumentSnapshot) {
40-
self.init(documentID: snapshot.documentID, data: snapshot.data())
41-
}
42-
43-
init?(from snapshot: DocumentSnapshot) {
44-
guard let data = snapshot.data() else { return nil }
45-
self.init(documentID: snapshot.documentID, data: data)
46-
}
47-
48-
private init?(documentID: String, data: [String: Any]) {
49-
guard
50-
let id = documentID as String?,
51-
let isPinned = data["isPinned"] as? Bool,
52-
let isCompleted = data["isCompleted"] as? Bool,
53-
let isChecked = data["isChecked"] as? Bool,
54-
let title = data["title"] as? String,
55-
let content = data["content"] as? String,
56-
let createdAtTimestamp = data["createdAt"] as? Timestamp,
57-
let updatedAtTimestamp = data["updatedAt"] as? Timestamp,
58-
let tags = data["tags"] as? [String],
59-
let kind = data["kind"] as? String else {
60-
return nil
61-
}
62-
self.id = id
63-
self.isPinned = isPinned
64-
self.isCompleted = isCompleted
65-
self.isChecked = isChecked
66-
self.title = title
67-
self.content = content
68-
self.createdAt = createdAtTimestamp.dateValue()
69-
self.updatedAt = updatedAtTimestamp.dateValue()
70-
if let dueDateTimestamp = data["dueDate"] as? Timestamp {
71-
self.dueDate = dueDateTimestamp.dateValue()
72-
} else {
73-
self.dueDate = nil
74-
}
75-
self.tags = tags
76-
self.kind = kind
77-
}
78-
7937
}

DevLog/Data/DTO/WebPageDTO.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by 최윤진 on 2/9/26.
66
//
77

8-
import FirebaseFirestore
8+
import Foundation
99

1010
struct WebPageRequest: Encodable {
1111
let title: String
@@ -14,8 +14,8 @@ struct WebPageRequest: Encodable {
1414
let imageURL: String
1515
}
1616

17-
struct WebPageResponse: Decodable {
18-
@DocumentID var id: String?
17+
struct WebPageResponse {
18+
let id: String?
1919
let title: String
2020
let url: String
2121
let displayURL: String

DevLog/Data/Mapper/PushNotificationMapping.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Created by 최윤진 on 2/27/26.
66
//
77

8-
import FirebaseFirestore
9-
108
extension PushNotificationResponse {
119
func toDomain() throws -> PushNotification {
1210
guard let id = self.id else {
@@ -20,7 +18,7 @@ extension PushNotificationResponse {
2018
id: id,
2119
title: self.title,
2220
body: self.body,
23-
receivedAt: self.receivedAt.dateValue(),
21+
receivedAt: self.receivedAt,
2422
isRead: self.isRead,
2523
todoID: self.todoID,
2624
todoKind: todoKind
@@ -31,14 +29,14 @@ extension PushNotificationResponse {
3129
extension PushNotificationCursorDTO {
3230
func toDomain() -> PushNotificationCursor {
3331
PushNotificationCursor(
34-
receivedAt: self.receivedAt.dateValue(),
32+
receivedAt: self.receivedAt,
3533
documentID: self.documentID
3634
)
3735
}
3836

3937
static func fromDomain(_ cursor: PushNotificationCursor) -> Self {
4038
PushNotificationCursorDTO(
41-
receivedAt: Timestamp(date: cursor.receivedAt),
39+
receivedAt: cursor.receivedAt,
4240
documentID: cursor.documentID
4341
)
4442
}

DevLog/Data/Mapper/TodoMapping.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Created by 최윤진 on 2/19/26.
66
//
77

8-
import FirebaseFirestore
9-
108
extension TodoRequest {
119
static func fromDomain(_ entity: Todo) -> Self {
1210
TodoRequest(
@@ -53,14 +51,14 @@ extension TodoResponse {
5351
extension TodoCursorDTO {
5452
func toDomain() -> TodoCursor {
5553
TodoCursor(
56-
createdAt: createdAt.dateValue(),
54+
createdAt: createdAt,
5755
documentID: documentID
5856
)
5957
}
6058

6159
static func fromDomain(_ cursor: TodoCursor) -> Self {
6260
TodoCursorDTO(
63-
createdAt: Timestamp(date: cursor.createdAt),
61+
createdAt: cursor.createdAt,
6462
documentID: cursor.documentID
6563
)
6664
}

DevLog/Infra/Extension/FirebaseAuthUser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import FirebaseAuth
1010

1111
extension FirebaseAuth.User {
12-
func toResponse(
12+
func makeResponse(
1313
providerID: AuthProviderID,
1414
fcmToken: String,
1515
accessToken: String? = nil

DevLog/Infra/Service/PushNotificationService.swift

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ final class PushNotificationService {
115115

116116
if let cursor {
117117
firestoreQuery = firestoreQuery.start(after: [
118-
cursor.receivedAt,
118+
Timestamp(date: cursor.receivedAt),
119119
cursor.documentID
120120
])
121121
}
@@ -124,17 +124,15 @@ final class PushNotificationService {
124124
.limit(to: query.pageSize)
125125
.getDocuments()
126126

127-
let items = try snapshot.documents.compactMap { document in
128-
try document.data(as: PushNotificationResponse.self)
129-
}
127+
let items = snapshot.documents.compactMap { makeResponse(from: $0) }
130128

131129
let nextCursor: PushNotificationCursorDTO? = snapshot.documents.last.map { document in
132130
guard let receivedAt = document.data()["receivedAt"] as? Timestamp else {
133131
return nil
134132
}
135133

136134
return PushNotificationCursorDTO(
137-
receivedAt: receivedAt,
135+
receivedAt: receivedAt.dateValue(),
138136
documentID: document.documentID
139137
)
140138
} ?? nil
@@ -177,3 +175,28 @@ final class PushNotificationService {
177175
logger.info("Successfully toggled notification read")
178176
}
179177
}
178+
179+
private extension PushNotificationService {
180+
func makeResponse(from snapshot: QueryDocumentSnapshot) -> PushNotificationResponse? {
181+
let data = snapshot.data()
182+
guard
183+
let title = data["title"] as? String,
184+
let body = data["body"] as? String,
185+
let receivedAt = data["receivedAt"] as? Timestamp,
186+
let isRead = data["isRead"] as? Bool,
187+
let todoID = data["todoID"] as? String,
188+
let todoKind = data["todoKind"] as? String else {
189+
return nil
190+
}
191+
192+
return PushNotificationResponse(
193+
id: snapshot.documentID,
194+
title: title,
195+
body: body,
196+
receivedAt: receivedAt.dateValue(),
197+
isRead: isRead,
198+
todoID: todoID,
199+
todoKind: todoKind
200+
)
201+
}
202+
}

DevLog/Infra/Service/SocialLogin/AppleAuthenticationService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ final class AppleAuthenticationService: AuthenticationService {
8181
let fcmToken = try await messaging.token()
8282

8383
logger.info("Successfully signed in with Apple")
84-
return result.user.toResponse(providerID: .apple, fcmToken: fcmToken)
84+
return result.user.makeResponse(providerID: .apple, fcmToken: fcmToken)
8585
} catch {
8686
logger.error("Failed to sign in with Apple", error: error)
8787
throw error

0 commit comments

Comments
 (0)