mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
Properly parse order direction (#2812)
This commit is contained in:
parent
7a22e71c69
commit
586c2f9ead
@ -171,6 +171,28 @@ func makeDecoder(iface interface{}) kithttp.DecodeRequestFunc {
|
||||
field.SetUint(uint64(queryValUint))
|
||||
case reflect.Bool:
|
||||
field.SetBool(queryVal == "1" || queryVal == "true")
|
||||
case reflect.Int:
|
||||
queryValInt := 0
|
||||
switch queryTagValue {
|
||||
case "order_direction":
|
||||
switch queryVal {
|
||||
case "desc":
|
||||
queryValInt = int(fleet.OrderDescending)
|
||||
case "asc":
|
||||
queryValInt = int(fleet.OrderAscending)
|
||||
case "":
|
||||
queryValInt = int(fleet.OrderAscending)
|
||||
default:
|
||||
return fleet.ListOptions{},
|
||||
errors.New("unknown order_direction: " + queryVal)
|
||||
}
|
||||
default:
|
||||
queryValInt, err = strconv.Atoi(queryVal)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "parsing uint from query")
|
||||
}
|
||||
}
|
||||
field.SetInt(int64(queryValInt))
|
||||
default:
|
||||
return nil, errors.Errorf("Cant handle type for field %s %s", f.Name, field.Kind())
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ func (s *integrationTestSuite) TestVulnerableSoftware() {
|
||||
|
||||
lsReq := listSoftwareRequest{}
|
||||
lsResp := listSoftwareResponse{}
|
||||
s.DoJSON("GET", "/api/v1/fleet/software", lsReq, http.StatusOK, &lsResp, "vulnerable", "true")
|
||||
s.DoJSON("GET", "/api/v1/fleet/software", lsReq, http.StatusOK, &lsResp, "vulnerable", "true", "order_key", "generated_cpe", "order_direction", "desc")
|
||||
assert.Len(t, lsResp.Software, 1)
|
||||
assert.Equal(t, soft1.ID, lsResp.Software[0].ID)
|
||||
assert.Len(t, lsResp.Software[0].Vulnerabilities, 1)
|
||||
|
Loading…
Reference in New Issue
Block a user