-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoMapping.swift
More file actions
70 lines (64 loc) · 1.78 KB
/
TodoMapping.swift
File metadata and controls
70 lines (64 loc) · 1.78 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
//
// TodoMapping.swift
// DevLog
//
// Created by 최윤진 on 2/19/26.
//
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,
dueDate: entity.dueDate,
tags: entity.tags,
kind: entity.kind
)
}
}
extension TodoResponse {
func toDomain() throws -> Todo {
guard let kind = TodoKind(rawValue: self.kind) else {
throw DataError.invalidData("TodoResponse.kind is invalid: \(self.kind)")
}
return Todo(
id: id,
isPinned: self.isPinned,
isCompleted: self.isCompleted,
isChecked: self.isChecked,
title: self.title,
content: self.content,
createdAt: self.createdAt,
updatedAt: self.updatedAt,
dueDate: self.dueDate,
tags: self.tags,
kind: kind
)
}
}
extension TodoCursorDTO {
func toDomain() -> TodoCursor {
TodoCursor(
createdAt: createdAt,
documentID: documentID
)
}
static func fromDomain(_ cursor: TodoCursor) -> Self {
TodoCursorDTO(
createdAt: cursor.createdAt,
documentID: cursor.documentID
)
}
}
extension TodoPageResponse {
func toDomain() throws -> TodoPage {
let items = try items.map { try $0.toDomain() }
let cursor = nextCursor?.toDomain()
return TodoPage(items: items, nextCursor: cursor)
}
}