-
Notifications
You must be signed in to change notification settings - Fork 5
/
settings.go
49 lines (38 loc) · 923 Bytes
/
settings.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
package searchrefiner
import (
"github.com/gin-gonic/gin"
"github.com/hscells/groove/combinator"
"net/http"
)
func GetSettings(s Server, c *gin.Context) Settings {
username := s.Perm.UserState().Username(c.Request)
var us Settings
if v, ok := s.Settings[username]; ok {
us = v
} else {
// Configure initial values for Settings struct.
}
return us
}
func (s Server) HandleSettings(c *gin.Context) {
c.HTML(http.StatusOK, "settings.html", GetSettings(s, c))
return
}
func (s Server) ApiSettingsRelevantSet(c *gin.Context) {
sets := GetSettings(s, c)
var rel []int64
err := c.BindJSON(&rel)
if err != nil {
c.String(http.StatusOK, err.Error())
return
}
d := make(combinator.Documents, len(rel))
for i, r := range rel {
d[i] = combinator.Document(r)
}
username := s.Perm.UserState().Username(c.Request)
sets.Relevant = d
s.Settings[username] = sets
c.Status(http.StatusOK)
return
}