-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfilter.go
More file actions
63 lines (54 loc) · 1.62 KB
/
filter.go
File metadata and controls
63 lines (54 loc) · 1.62 KB
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
package blnkgo
import (
"encoding/json"
"fmt"
)
type Operator string
const (
OpEqual Operator = "eq"
OpNotEqual Operator = "ne"
OpGreaterThan Operator = "gt"
OpGreaterThanOrEqual Operator = "gte"
OpLessThan Operator = "lt"
OpLessThanOrEqual Operator = "lte"
OpIn Operator = "in"
OpBetween Operator = "between"
OpLike Operator = "like"
OpILike Operator = "ilike"
OpIsNull Operator = "isnull"
OpIsNotNull Operator = "isnotnull"
)
type FilterParams struct {
Filters []Filter `json:"filters"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
SortBy string `json:"sort_by,omitempty"`
SortOrder string `json:"sort_order,omitempty"`
IncludeCount bool `json:"include_count,omitempty"`
}
type Filter struct {
Field string `json:"field"`
Operator Operator `json:"operator"`
Value interface{} `json:"value,omitempty"`
Values []interface{} `json:"values,omitempty"`
}
type FilterResponse struct {
Data interface{} `json:"data"`
TotalCount *int64 `json:"total_count,omitempty"`
}
func (f *FilterResponse) UnmarshalJSON(data []byte) error {
type alias FilterResponse
var aux alias
if err := json.Unmarshal(data, &aux); err == nil && aux.Data != nil {
f.Data = aux.Data
f.TotalCount = aux.TotalCount
return nil
}
var slice []interface{}
if err := json.Unmarshal(data, &slice); err != nil {
return fmt.Errorf("failed to decode FilterResponse: %w", err)
}
f.Data = slice
f.TotalCount = nil
return nil
}