-
Notifications
You must be signed in to change notification settings - Fork 0
/
show.go
74 lines (57 loc) · 1.56 KB
/
show.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package show
import (
"fmt"
"net/http"
"strconv"
"github.com/alrusov/stdhttp"
"github.com/alrusov/balance-collector/internal/entity"
"github.com/alrusov/balance-collector/internal/show/dashboard"
"github.com/alrusov/balance-collector/internal/show/history"
)
//----------------------------------------------------------------------------------------------------------------------------//
// Show --
func Show(id uint64, prefix string, path string, w http.ResponseWriter, r *http.Request) (processed bool) {
processed = true
var err error
defer func() {
if err != nil {
stdhttp.Error(id, false, w, http.StatusInternalServerError, "Server error", err)
}
}()
err = r.ParseForm()
if err != nil {
return
}
returnToMain := true
switch r.Form.Get("op") {
case "update-all":
entity.Update(fmt.Sprintf("%d", id), true)
case "repeat":
entity.Repeat(fmt.Sprintf("%d", id))
case "history":
entityID, e := strconv.ParseUint(r.Form.Get("id"), 10, 32)
if e != nil {
err = e
} else {
err = history.Do(id, w, r, uint(entityID))
returnToMain = false
}
case "update":
entityID, e := strconv.ParseUint(r.Form.Get("id"), 10, 32)
if e != nil {
err = e
} else {
entity.UpdateByID(fmt.Sprintf("%d", id), uint(entityID))
}
case "":
fallthrough
default:
err = dashboard.Do(id, w, r)
returnToMain = false
}
if returnToMain {
stdhttp.ReturnRefresh(id, w, r, http.StatusOK, path, nil, nil)
}
return
}
//----------------------------------------------------------------------------------------------------------------------------//