-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo.go
50 lines (44 loc) · 1.03 KB
/
todo.go
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
package response
import (
"github.com/sajjad1993/todo/internal/gateway/domain/todo"
"sort"
)
type ListToDOListResponse struct {
Lists []*List `json:"lists"`
}
type Item struct {
ID uint `json:"id"`
Title string `json:"title"`
Priority uint `json:"priority"`
}
type List struct {
ID uint `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Items []*Item `json:"items"`
}
type TodoLists []*List
func (l TodoLists) FromEntity(lists []*todo.List) TodoLists {
for _, list := range lists {
todoList := &List{
ID: list.ID,
Name: list.Name,
Description: list.Description,
}
for _, item := range list.Todos {
todoItem := &Item{
ID: item.ID,
Title: item.Title,
Priority: item.Priority,
}
todoList.Items = append(todoList.Items, todoItem)
sort.Slice(todoList.Items,
func(i, j int) bool {
return todoList.Items[i].Priority < todoList.Items[j].Priority
},
)
}
l = append(l, todoList)
}
return l
}