-
Notifications
You must be signed in to change notification settings - Fork 1
/
bookmark.go
43 lines (38 loc) · 982 Bytes
/
bookmark.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
package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/rkonfj/lln/state"
"github.com/rkonfj/lln/tools"
)
func bookmarkStatus(w http.ResponseWriter, r *http.Request) {
err := state.BookmarkStatus(currentSessionUser(r), chi.URLParam(r, tools.StatusID))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
}
}
func listBookmarks(w http.ResponseWriter, r *http.Request) {
opts, err := tools.URLPaginationOptions(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, err.Error())
return
}
user := currentSessionUser(r)
ss, more := state.ListBookmarks(user, opts)
var ret []*Status
for _, s := range ss {
status := castStatus(s, user)
if len(s.RefStatus) > 0 {
prev := state.GetStatus(s.RefStatus)
if prev != nil {
status.RefStatus = castStatus(prev, user)
}
}
ret = append(ret, status)
}
json.NewEncoder(w).Encode(L{V: ret, More: more})
}