-
Notifications
You must be signed in to change notification settings - Fork 1
/
managers.go
43 lines (34 loc) · 795 Bytes
/
managers.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
package deferr
import (
"strings"
"github.com/nu7hatch/gouuid"
)
type TodoManager struct {
todoRepo TodoAdapter
}
func NewTodoManager(todoRepo TodoAdapter) *TodoManager {
return &TodoManager{todoRepo: todoRepo}
}
func (tm *TodoManager) List() []*Todo {
return tm.todoRepo.List()
}
func (tm *TodoManager) Push(t *Todo) error {
t.Slug = tm.getSlug()
return tm.todoRepo.Push(t)
}
// Removes the first item on the list
func (tm *TodoManager) Pop() (*Todo, error) {
t, err := tm.todoRepo.Pop()
if err != nil {
return nil, err
}
return t, nil
}
// Defers the first item down to the bottom
func (tm *TodoManager) Defer() error {
return tm.todoRepo.Defer()
}
func (tm *TodoManager) getSlug() string {
uuid, _ := uuid.NewV4()
return strings.Replace(uuid.String(), "-", "", -1)
}