Skip to content

Commit d765fc2

Browse files
committed
refactor: 위젯 스냅샷 데이터 모델 분리
1 parent da78bd8 commit d765fc2

11 files changed

Lines changed: 93 additions & 70 deletions

File tree

Application/DevLogData/Sources/DTO/TodoDTO.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
import Foundation
9-
import DevLogDomain
109

1110
public struct TodoRequest: Encodable {
1211
public let id: String
@@ -102,3 +101,34 @@ public struct TodoResponse {
102101
self.category = category
103102
}
104103
}
104+
105+
public struct WidgetTodoSnapshot: Equatable {
106+
public let id: String
107+
public let number: Int?
108+
public let title: String
109+
public let isPinned: Bool
110+
public let createdAt: Date
111+
public let completedAt: Date?
112+
public let deletedAt: Date?
113+
public let dueDate: Date?
114+
115+
public init(
116+
id: String,
117+
number: Int?,
118+
title: String,
119+
isPinned: Bool,
120+
createdAt: Date,
121+
completedAt: Date?,
122+
deletedAt: Date?,
123+
dueDate: Date?
124+
) {
125+
self.id = id
126+
self.number = number
127+
self.title = title
128+
self.isPinned = isPinned
129+
self.createdAt = createdAt
130+
self.completedAt = completedAt
131+
self.deletedAt = deletedAt
132+
self.dueDate = dueDate
133+
}
134+
}

Application/DevLogData/Sources/Mapper/TodoMapping.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ public extension TodoResponse {
5757
}
5858
}
5959

60+
public extension WidgetTodoSnapshot {
61+
static func fromDomain(_ todo: Todo) -> Self {
62+
WidgetTodoSnapshot(
63+
id: todo.id,
64+
number: todo.number,
65+
title: todo.title,
66+
isPinned: todo.isPinned,
67+
createdAt: todo.createdAt,
68+
completedAt: todo.completedAt,
69+
deletedAt: todo.deletedAt,
70+
dueDate: todo.dueDate
71+
)
72+
}
73+
}
74+
6075
public extension TodoCursorDTO {
6176
func toDomain() -> TodoCursor {
6277
TodoCursor(

Application/DevLogData/Sources/Protocol/WidgetSnapshotUpdater.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@
77

88
import Foundation
99
import DevLogCore
10-
import DevLogDomain
1110

1211
public protocol WidgetSnapshotUpdater {
1312
func updateTodaySnapshot(
14-
todos: [Todo],
13+
todos: [WidgetTodoSnapshot],
1514
now: Date
1615
)
1716
func updateTodaySnapshot(
18-
todos: [Todo],
17+
todos: [WidgetTodoSnapshot],
1918
displayOptions: TodayDisplayOptions,
2019
now: Date
2120
)
2221
func updateHeatmapSnapshot(
23-
createdTodos: [Todo],
24-
completedTodos: [Todo],
25-
deletedTodos: [Todo],
22+
createdTodos: [WidgetTodoSnapshot],
23+
completedTodos: [WidgetTodoSnapshot],
24+
deletedTodos: [WidgetTodoSnapshot],
2625
quarterStart: Date,
2726
now: Date
2827
)

Application/DevLogPersistence/Sources/Persistence/WidgetSnapshotUpdaterImpl.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import Foundation
99
import WidgetKit
1010
import DevLogCore
11-
import DevLogDomain
1211
import DevLogData
1312
import DevLogWidgetCore
1413

@@ -32,7 +31,7 @@ final class WidgetSnapshotUpdaterImpl: WidgetSnapshotUpdater {
3231
}
3332

3433
func updateTodaySnapshot(
35-
todos: [Todo],
34+
todos: [WidgetTodoSnapshot],
3635
now: Date = Date()
3736
) {
3837
updateTodaySnapshot(
@@ -43,7 +42,7 @@ final class WidgetSnapshotUpdaterImpl: WidgetSnapshotUpdater {
4342
}
4443

4544
func updateTodaySnapshot(
46-
todos: [Todo],
45+
todos: [WidgetTodoSnapshot],
4746
displayOptions: TodayDisplayOptions,
4847
now: Date = Date()
4948
) {
@@ -65,9 +64,9 @@ final class WidgetSnapshotUpdaterImpl: WidgetSnapshotUpdater {
6564
}
6665

6766
func updateHeatmapSnapshot(
68-
createdTodos: [Todo],
69-
completedTodos: [Todo],
70-
deletedTodos: [Todo],
67+
createdTodos: [WidgetTodoSnapshot],
68+
completedTodos: [WidgetTodoSnapshot],
69+
deletedTodos: [WidgetTodoSnapshot],
7170
quarterStart: Date,
7271
now: Date = Date()
7372
) {

Application/DevLogPersistence/Tests/Persistence/WidgetSnapshotUpdaterTests.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99
import DevLogCore
10-
import DevLogDomain
10+
import DevLogData
1111
import Testing
1212
@testable import DevLogPersistence
1313
@testable import DevLogWidgetCore
@@ -150,22 +150,16 @@ struct WidgetSnapshotUpdaterTests {
150150
completedAt: Date? = nil,
151151
deletedAt: Date? = nil,
152152
dueDate: Date? = nil
153-
) -> Todo {
154-
Todo(
153+
) -> WidgetTodoSnapshot {
154+
WidgetTodoSnapshot(
155155
id: id,
156-
isPinned: false,
157-
isCompleted: completedAt != nil,
158-
isChecked: false,
159156
number: 1,
160157
title: id,
161-
content: "",
158+
isPinned: false,
162159
createdAt: createdAt,
163-
updatedAt: createdAt,
164160
completedAt: completedAt,
165161
deletedAt: deletedAt,
166-
dueDate: dueDate,
167-
tags: [],
168-
category: .system(.feature)
162+
dueDate: dueDate
169163
)
170164
}
171165
}

Widget/DevLogWidgetCore/Sources/Heatmap/HeatmapWidgetSnapshotFactory.swift

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

88
import Foundation
99
import DevLogCore
10-
import DevLogDomain
1110
import DevLogData
1211

1312
public struct HeatmapWidgetSnapshotFactory {
@@ -35,9 +34,9 @@ public struct HeatmapWidgetSnapshotFactory {
3534
}
3635

3736
public func makeSnapshot(
38-
createdTodos: [Todo],
39-
completedTodos: [Todo],
40-
deletedTodos: [Todo],
37+
createdTodos: [WidgetTodoSnapshot],
38+
completedTodos: [WidgetTodoSnapshot],
39+
deletedTodos: [WidgetTodoSnapshot],
4140
selectedActivityKinds: Set<ActivityKind>,
4241
quarterStart: Date,
4342
now: Date = Date()
@@ -79,9 +78,9 @@ public struct HeatmapWidgetSnapshotFactory {
7978

8079
private extension HeatmapWidgetSnapshotFactory {
8180
func makeDailyCountsByDate(
82-
createdTodos: [Todo],
83-
completedTodos: [Todo],
84-
deletedTodos: [Todo],
81+
createdTodos: [WidgetTodoSnapshot],
82+
completedTodos: [WidgetTodoSnapshot],
83+
deletedTodos: [WidgetTodoSnapshot],
8584
quarterStart: Date,
8685
nextQuarterStart: Date
8786
) -> [Date: DailyCounts] {

Widget/DevLogWidgetCore/Sources/Sync/WidgetSyncEventHandler.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private extension WidgetSyncEventHandler {
6464
todosWithoutDueDate
6565
)
6666
snapshotUpdater.updateTodaySnapshot(
67-
todos: todayTodosWithDueDate + todayTodosWithoutDueDate,
67+
todos: (todayTodosWithDueDate + todayTodosWithoutDueDate).map(WidgetTodoSnapshot.fromDomain),
6868
now: Date()
6969
)
7070
} catch {
@@ -104,9 +104,9 @@ private extension WidgetSyncEventHandler {
104104
deletedTodos
105105
)
106106
snapshotUpdater.updateHeatmapSnapshot(
107-
createdTodos: createdTodoItems,
108-
completedTodos: completedTodoItems,
109-
deletedTodos: deletedTodoItems,
107+
createdTodos: createdTodoItems.map(WidgetTodoSnapshot.fromDomain),
108+
completedTodos: completedTodoItems.map(WidgetTodoSnapshot.fromDomain),
109+
deletedTodos: deletedTodoItems.map(WidgetTodoSnapshot.fromDomain),
110110
quarterStart: quarterStart,
111111
now: currentDate
112112
)

Widget/DevLogWidgetCore/Sources/Today/TodayWidgetSnapshotFactory.swift

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

88
import Foundation
99
import DevLogCore
10-
import DevLogDomain
1110
import DevLogData
1211

1312
public struct TodayWidgetSnapshotFactory {
@@ -49,7 +48,7 @@ public struct TodayWidgetSnapshotFactory {
4948
let isPinned: Bool
5049
let dueDate: Date?
5150

52-
init?(from todo: Todo) {
51+
init?(from todo: WidgetTodoSnapshot) {
5352
guard let number = todo.number else { return nil }
5453
self.id = todo.id
5554
self.number = number
@@ -71,7 +70,7 @@ public struct TodayWidgetSnapshotFactory {
7170
}
7271

7372
public func makeSnapshot(
74-
todos: [Todo],
73+
todos: [WidgetTodoSnapshot],
7574
displayOptions: TodayDisplayOptions,
7675
now: Date = Date()
7776
) -> TodayWidgetSnapshot {

Widget/DevLogWidgetCore/Tests/Heatmap/HeatmapWidgetSnapshotFactoryTests.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99
import Testing
1010
import DevLogCore
11-
import DevLogDomain
11+
import DevLogData
1212
@testable import DevLogWidgetCore
1313

1414
struct HeatmapWidgetSnapshotFactoryTests {
@@ -216,22 +216,16 @@ struct HeatmapWidgetSnapshotFactoryTests {
216216
createdAt: Date,
217217
completedAt: Date? = nil,
218218
deletedAt: Date? = nil
219-
) -> Todo {
220-
Todo(
219+
) -> WidgetTodoSnapshot {
220+
WidgetTodoSnapshot(
221221
id: id,
222-
isPinned: false,
223-
isCompleted: completedAt != nil,
224-
isChecked: false,
225222
number: 1,
226223
title: id,
227-
content: "",
224+
isPinned: false,
228225
createdAt: createdAt,
229-
updatedAt: createdAt,
230226
completedAt: completedAt,
231227
deletedAt: deletedAt,
232-
dueDate: nil,
233-
tags: [],
234-
category: .system(.feature)
228+
dueDate: nil
235229
)
236230
}
237231
}

Widget/DevLogWidgetCore/Tests/Sync/WidgetSyncEventHandlerTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ private actor WidgetSyncTodoRepositorySpy: TodoRepository {
247247

248248
private final class WidgetSnapshotUpdaterSpy: WidgetSnapshotUpdater {
249249
struct TodayUpdate {
250-
let todos: [Todo]
250+
let todos: [WidgetTodoSnapshot]
251251
let displayOptions: TodayDisplayOptions?
252252
let now: Date
253253
}
254254

255255
struct HeatmapUpdate {
256-
let createdTodos: [Todo]
257-
let completedTodos: [Todo]
258-
let deletedTodos: [Todo]
256+
let createdTodos: [WidgetTodoSnapshot]
257+
let completedTodos: [WidgetTodoSnapshot]
258+
let deletedTodos: [WidgetTodoSnapshot]
259259
let quarterStart: Date
260260
let now: Date
261261
}
@@ -286,7 +286,7 @@ private final class WidgetSnapshotUpdaterSpy: WidgetSnapshotUpdater {
286286
}
287287

288288
func updateTodaySnapshot(
289-
todos: [Todo],
289+
todos: [WidgetTodoSnapshot],
290290
now: Date
291291
) {
292292
appendTodayUpdate(
@@ -299,7 +299,7 @@ private final class WidgetSnapshotUpdaterSpy: WidgetSnapshotUpdater {
299299
}
300300

301301
func updateTodaySnapshot(
302-
todos: [Todo],
302+
todos: [WidgetTodoSnapshot],
303303
displayOptions: TodayDisplayOptions,
304304
now: Date
305305
) {
@@ -313,9 +313,9 @@ private final class WidgetSnapshotUpdaterSpy: WidgetSnapshotUpdater {
313313
}
314314

315315
func updateHeatmapSnapshot(
316-
createdTodos: [Todo],
317-
completedTodos: [Todo],
318-
deletedTodos: [Todo],
316+
createdTodos: [WidgetTodoSnapshot],
317+
completedTodos: [WidgetTodoSnapshot],
318+
deletedTodos: [WidgetTodoSnapshot],
319319
quarterStart: Date,
320320
now: Date
321321
) {

0 commit comments

Comments
 (0)