-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoMapping.swift
More file actions
118 lines (108 loc) · 3.33 KB
/
Copy pathTodoMapping.swift
File metadata and controls
118 lines (108 loc) · 3.33 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// TodoMapping.swift
// DevLogData
//
// Created by 최윤진 on 2/19/26.
//
import DevLogCore
import DevLogDomain
public extension TodoRequest {
static func fromDomain(_ todo: Todo) -> Self {
TodoRequest(
id: todo.id,
isPinned: todo.isPinned,
isCompleted: todo.isCompleted,
isChecked: todo.isChecked,
title: todo.title,
content: todo.content,
createdAt: todo.createdAt,
updatedAt: todo.updatedAt,
completedAt: todo.completedAt,
deletedAt: todo.deletedAt,
dueDate: todo.dueDate,
tags: todo.tags,
category: todo.category.storageValue
)
}
static func fromDomain(_ todoDraft: TodoDraft) -> Self {
TodoRequest(
id: todoDraft.id,
isPinned: todoDraft.isPinned,
isCompleted: todoDraft.isCompleted,
isChecked: todoDraft.isChecked,
title: todoDraft.title,
content: todoDraft.content,
createdAt: todoDraft.createdAt,
updatedAt: todoDraft.updatedAt,
completedAt: todoDraft.completedAt,
deletedAt: nil,
dueDate: todoDraft.dueDate,
tags: todoDraft.tags,
category: todoDraft.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)
}
}