forked from labd/commercetools-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_queryinput.go
73 lines (60 loc) · 2.24 KB
/
client_queryinput.go
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
62
63
64
65
66
67
68
69
70
71
72
73
package commercetools
import (
"net/url"
"strconv"
)
// QueryInput provides the data required to query types.
type QueryInput struct {
// The queryable APIs support ad-hoc filtering of resources through flexible
// predicates. They do so via the where query parameter that accepts a
// predicate expression to determine whether a specific resource
// representation should be included in the result. The structure of
// predicates and the names of the fields follow the structure and naming of
// the fields in the documented response representation of the query
// results.
// https://docs.commercetools.com/http-api-query-predicates.html
Where string
// A query endpoint that supports sorting does so through the sort query
// parameter. The provided value must be a valid sort expression. The
// default sort direction is ASC. The allowed sort paths are typically
// listed on the specific query endpoints. If multiple sort expressions are
// specified via multiple sort parameters, they are combined into a composed
// sort where the results are first sorted by the first expression, followed
// by equal values being sorted according to the second expression, and so
// on.
// https://docs.commercetools.com/http-api.html#sorting
Sort []string
// Reference expansion is a feature of the resources listed in the table
// below that enables clients to request server-side expansion of Reference
// resources, thereby reducing the number of required client-server
// roundtrips to obtain the data that a client needs for a specific
// use-case. Reference expansion can be used when creating, updating,
// querying, and deleting these resources.
// https://docs.commercetools.com/http-api.html#reference-expansion
Expand string
Limit int
Offset int
FilterQuery string
}
func (qi QueryInput) toParams() (values url.Values) {
values = url.Values{}
if qi.Where != "" {
values.Set("where", qi.Where)
}
for i := range qi.Sort {
values.Add("sort", qi.Sort[i])
}
if qi.Expand != "" {
values.Set("expand", qi.Expand)
}
if qi.Limit != 0 {
values.Set("limit", strconv.Itoa(qi.Limit))
}
if qi.Offset != 0 {
values.Set("offset", strconv.Itoa(qi.Offset))
}
if qi.FilterQuery != ""{
values.Set("filter", qi.FilterQuery)
}
return
}