Fix sorting on multiple ticket fields (#412)

This commit is contained in:
Jonas Plum
2022-08-21 22:23:27 +02:00
committed by GitHub
parent 2b7be7c212
commit fd8e793361
4 changed files with 130 additions and 34 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"strconv"
"strings"
"github.com/go-chi/chi"
"github.com/xeipuuv/gojsonschema"
@@ -58,30 +59,12 @@ func parseQueryBool(r *http.Request, s string) (bool, error) {
}
func parseQueryStringArray(r *http.Request, key string) ([]string, error) {
stringArray, ok := r.URL.Query()[key]
if !ok {
return nil, nil
}
return removeEmpty(stringArray), nil
}
func removeEmpty(l []string) []string {
var stringArray []string
for _, s := range l {
if s == "" {
continue
}
stringArray = append(stringArray, s)
}
return stringArray
return parseQueryArray(r, key), nil
}
func parseQueryBoolArray(r *http.Request, key string) ([]bool, error) {
stringArray, ok := r.URL.Query()[key]
if !ok {
return nil, nil
}
stringArray := parseQueryArray(r, key)
var boolArray []bool
for _, s := range stringArray {
if s == "" {
@@ -97,6 +80,33 @@ func parseQueryBoolArray(r *http.Request, key string) ([]bool, error) {
return boolArray, nil
}
func parseQueryArray(r *http.Request, key string) []string {
stringArray, ok := r.URL.Query()[key]
if !ok {
return nil
}
if len(stringArray) == 0 {
return nil
}
stringArray = strings.Split(stringArray[0], ",")
return removeEmpty(stringArray)
}
func removeEmpty(l []string) []string {
var stringArray []string
for _, s := range l {
if s == "" {
continue
}
stringArray = append(stringArray, s)
}
return stringArray
}
func parseQueryOptionalInt(r *http.Request, key string) (*int, error) {
s := r.URL.Query().Get(key)
if s == "" {