nidus-sync/resource/query_params.go

30 lines
585 B
Go
Raw Permalink Normal View History

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 (
// "github.com/gorilla/schema"
2026-04-01 18:12:46 +00:00
)
type QueryParams struct {
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
}
a := s[0] != '-'
2026-03-10 15:46:17 +00:00
if s[0] == '+' || s[0] == '-' {
s = s[1:]
}
return s, a
}