-
Notifications
You must be signed in to change notification settings - Fork 0
/
complete.go
58 lines (46 loc) 路 1.04 KB
/
complete.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
51
52
53
54
55
56
57
58
package cli
import (
"errors"
"github.com/beauxarts/fedorov/data"
"github.com/boggydigital/nod"
"net/url"
"strings"
)
const (
SetComplete = "set"
ClearComplete = "clear"
)
func CompleteHandler(u *url.URL) error {
var ids []string
if idstr := u.Query().Get("id"); idstr != "" {
ids = strings.Split(idstr, ",")
}
action := u.Query().Get("action")
return Complete(ids, action)
}
func Complete(ids []string, action string) error {
ca := nod.NewProgress("%s complete...", action)
defer ca.End()
rdx, err := data.NewReduxWriter(data.BookCompletedProperty)
if err != nil {
return err
}
ca.TotalInt(len(ids))
for _, id := range ids {
switch action {
case SetComplete:
if err := rdx.ReplaceValues(data.BookCompletedProperty, id, "true"); err != nil {
return err
}
case ClearComplete:
if err := rdx.CutValues(data.BookCompletedProperty, id, "true"); err != nil {
return err
}
default:
return errors.New("unknown compelte action " + action)
}
ca.Increment()
}
ca.EndWithResult("done")
return nil
}