-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathquery_params.go
More file actions
61 lines (47 loc) · 1.16 KB
/
query_params.go
File metadata and controls
61 lines (47 loc) · 1.16 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
57
58
59
60
61
package helpers
import (
"net/url"
"slices"
"strconv"
"github.com/semaphoreui/semaphore/db"
)
func QueryParamsForProps(url *url.URL, props db.ObjectProps) (params db.RetrieveQueryParams) {
sortBy := ""
if url.Query().Get("sort") != "" {
i := slices.Index(props.SortableColumns, url.Query().Get("sort"))
if i != -1 {
sortBy = props.SortableColumns[i]
}
}
params = db.RetrieveQueryParams{
SortBy: sortBy,
SortInverted: url.Query().Get("order") == "desc",
}
return
}
func QueryParams(url *url.URL) db.RetrieveQueryParams {
return db.RetrieveQueryParams{
SortBy: url.Query().Get("sort"),
SortInverted: url.Query().Get("order") == "desc",
}
}
func QueryParamsWithOwner(url *url.URL, props db.ObjectProps) db.RetrieveQueryParams {
res := QueryParamsForProps(url, props)
hasOwnerFilter := false
for _, ownership := range props.Ownerships {
s := url.Query().Get(ownership.ReferringColumnSuffix)
if s == "" {
continue
}
id, err2 := strconv.Atoi(s)
if err2 != nil {
continue
}
res.Ownership.SetOwnerID(*ownership, id)
hasOwnerFilter = true
}
if !hasOwnerFilter {
res.Ownership.WithoutOwnerOnly = true
}
return res
}