-
Notifications
You must be signed in to change notification settings - Fork 4
/
model.go
44 lines (39 loc) · 984 Bytes
/
model.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
package main
import (
"fmt"
"time"
"github.com/google/uuid"
"github.com/nanobox-io/golang-scribble"
)
type ToDo struct {
UID string `json:"id"`
Name string `json:"name"`
Created string `json:"created"`
Done string `json:"done"`
}
//type ToDoCollection []ToDo
//func (toDos *ToDoCollection) getAll(db *scribble.Driver) {
// records, _ := db.ReadAll("toDo")
//
// for _, record := range records{
// toDo := ToDo{}
// json.Unmarshal([]byte(record), &toDo)
// *toDos=append(*toDos, toDo)
// }
//}
func (toDo *ToDo) getToDo(db *scribble.Driver) {
db.Read("toDo", toDo.UID, &toDo)
}
func (toDo *ToDo) putToDo(db *scribble.Driver) {
if toDo.UID == "" {
toDo.UID = uuid.Must(uuid.NewRandom()).String()
}
db.Write("toDo", toDo.UID, toDo)
}
func (toDo *ToDo) finish(db *scribble.Driver) {
if toDo.UID == "" {
fmt.Println("This todo cannot be finished as it does not exist yet")
}
toDo.Done = time.Now().String()
db.Write("toDo", toDo.UID, toDo)
}