2026-04-01 18:12:46 +00:00
|
|
|
package resource
|
2026-03-10 15:46:17 +00:00
|
|
|
|
2026-04-01 18:12:46 +00:00
|
|
|
import (
|
2026-04-05 21:57:30 +00:00
|
|
|
// "github.com/gorilla/schema"
|
2026-04-01 18:12:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type QueryParams struct {
|
2026-04-05 21:57:30 +00:00
|
|
|
Limit *int `schema:"limit"`
|
|
|
|
|
OrganizationID *int `schema:"org"`
|
|
|
|
|
Query *string `schema:"query"`
|
|
|
|
|
Sort *string `schema:"sort"`
|
|
|
|
|
Type *string `schema:"type"`
|
2026-03-10 15:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-01 18:12:46 +00:00
|
|
|
func (qp QueryParams) SortOrDefault(default_name string, ascending bool) (string, bool) {
|
2026-03-10 15:46:17 +00:00
|
|
|
if qp.Sort == nil {
|
|
|
|
|
return default_name, ascending
|
|
|
|
|
}
|
|
|
|
|
s := *qp.Sort
|
|
|
|
|
if s == "" {
|
|
|
|
|
return default_name, ascending
|
|
|
|
|
}
|
2026-05-01 21:27:17 +00:00
|
|
|
a := s[0] != '-'
|
2026-05-01 20:49:37 +00:00
|
|
|
|
2026-03-10 15:46:17 +00:00
|
|
|
if s[0] == '+' || s[0] == '-' {
|
|
|
|
|
s = s[1:]
|
|
|
|
|
}
|
|
|
|
|
return s, a
|
|
|
|
|
}
|