-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.go
More file actions
56 lines (45 loc) · 1.18 KB
/
index.go
File metadata and controls
56 lines (45 loc) · 1.18 KB
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
package main
import (
"net/http"
"strconv"
"app/session"
"app/templates"
)
const defaultPageSize = 30
func (h *handler) indexView(w http.ResponseWriter, r *http.Request) error {
s := session.GetSession(r.Context())
if s.UserID == 0 {
return templates.Login().Render(r.Context(), w)
}
rq := r.URL.Query()
rawPage := rq.Get("page")
currentPage, err := strconv.ParseInt(rawPage, 10, 64)
if err != nil {
currentPage = 1
}
if currentPage <= 0 {
currentPage = 1
}
stateVals, state, order, err := readableStateToDBValues(rq.Get("state"), StateFilterPending)
if err != nil {
return err
}
t := rq.Get("type")
switch t {
case "", "subject":
return h.listSubjectPatches(w, r, state, order, stateVals, currentPage)
case "episode":
return h.listEpisodePatches(w, r, state, order, stateVals, currentPage)
}
http.Error(w, "invalid patch type", http.StatusBadRequest)
return nil
}
const PatchStatePending = 0
const PatchStateAccepted = 1
const PatchStateRejected = 2
const PatchStateOutdated = 3
const StateFilterPending = "pending"
const StateFilterReviewed = "reviewed"
const StateFilterAll = "all"
const StateFilterRejected = "rejected"
const StateFilterAccepted = "accepted"