-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoMapping.swift
More file actions
99 lines (90 loc) · 2.72 KB
/
Copy pathTodoMapping.swift
File metadata and controls
99 lines (90 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// TodoMapping.swift
// DevLogData
//
// Created by 최윤진 on 2/19/26.
//
import DevLogDomain
public extension TodoRequest {
static func fromDomain(_ entity: Todo) -> Self {
TodoRequest(
id: entity.id,
isPinned: entity.isPinned,
isCompleted: entity.isCompleted,
isChecked: entity.isChecked,
title: entity.title,
content: entity.content,
createdAt: entity.createdAt,
updatedAt: entity.updatedAt,
completedAt: entity.completedAt,
deletedAt: entity.deletedAt,
dueDate: entity.dueDate,
tags: entity.tags,
category: entity.category.storageValue
)
}
}
public extension TodoResponse {
func toDomain() throws -> Todo {
let todoCategory: TodoCategory
switch category {
case .decoded(let category):
todoCategory = category
case .raw(let category):
throw DataError.invalidData("TodoResponse.category must be resolved before toDomain(): \(category)")
}
return Todo(
id: id,
isPinned: self.isPinned,
isCompleted: self.isCompleted,
isChecked: self.isChecked,
number: self.number,
title: self.title,
content: self.content,
createdAt: self.createdAt,
updatedAt: self.updatedAt,
completedAt: self.completedAt,
deletedAt: self.deletedAt,
dueDate: self.dueDate,
tags: self.tags,
category: todoCategory
)
}
}
public extension WidgetTodoSnapshot {
static func fromDomain(_ todo: Todo) -> Self {
WidgetTodoSnapshot(
id: todo.id,
number: todo.number,
title: todo.title,
isPinned: todo.isPinned,
createdAt: todo.createdAt,
completedAt: todo.completedAt,
deletedAt: todo.deletedAt,
dueDate: todo.dueDate
)
}
}
public extension TodoCursorDTO {
func toDomain() -> TodoCursor {
TodoCursor(
primarySortDate: primarySortDate,
secondarySortDate: secondarySortDate,
documentID: documentID
)
}
static func fromDomain(_ cursor: TodoCursor) -> Self {
TodoCursorDTO(
primarySortDate: cursor.primarySortDate,
secondarySortDate: cursor.secondarySortDate,
documentID: cursor.documentID
)
}
}
public extension TodoPageResponse {
func toDomain() throws -> TodoPage {
let items = try items.map { try $0.toDomain() }
let cursor = nextCursor?.toDomain()
return TodoPage(items: items, nextCursor: cursor)
}
}