-
Notifications
You must be signed in to change notification settings - Fork 82
/
filter.go
190 lines (162 loc) · 6.84 KB
/
filter.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package notionapi
import (
"encoding/json"
)
type FilterOperator string
type Filter interface {
filter()
}
type CompoundFilter map[FilterOperator][]PropertyFilter
type AndCompoundFilter []Filter
type OrCompoundFilter []Filter
func (f AndCompoundFilter) filter() {}
func (f OrCompoundFilter) filter() {}
func (f AndCompoundFilter) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
And []Filter `json:"and"`
}{
And: f,
})
}
func (f OrCompoundFilter) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Or []Filter `json:"or"`
}{
Or: f,
})
}
type Condition string
type TimestampFilter struct {
Timestamp TimestampType `json:"timestamp"`
CreatedTime *DateFilterCondition `json:"created_time,omitempty"`
LastEditedTime *DateFilterCondition `json:"last_edited_time,omitempty"`
}
func (f TimestampFilter) filter() {}
type PropertyFilter struct {
Property string `json:"property"`
RichText *TextFilterCondition `json:"rich_text,omitempty"`
Number *NumberFilterCondition `json:"number,omitempty"`
Checkbox *CheckboxFilterCondition `json:"checkbox,omitempty"`
Select *SelectFilterCondition `json:"select,omitempty"`
MultiSelect *MultiSelectFilterCondition `json:"multi_select,omitempty"`
Date *DateFilterCondition `json:"date,omitempty"`
People *PeopleFilterCondition `json:"people,omitempty"`
Files *FilesFilterCondition `json:"files,omitempty"`
Relation *RelationFilterCondition `json:"relation,omitempty"`
Formula *FormulaFilterCondition `json:"formula,omitempty"`
Rollup *RollupFilterCondition `json:"rollup,omitempty"`
Status *StatusFilterCondition `json:"status,omitempty"`
UniqueId *UniqueIdFilterCondition `json:"unique_id,omitempty"`
}
func (f PropertyFilter) filter() {}
type SearchFilter struct {
Value string `json:"value"`
Property string `json:"property"`
}
type TextFilterCondition struct {
Equals string `json:"equals,omitempty"`
DoesNotEqual string `json:"does_not_equal,omitempty"`
Contains string `json:"contains,omitempty"`
DoesNotContain string `json:"does_not_contain,omitempty"`
StartsWith string `json:"starts_with,omitempty"`
EndsWith string `json:"ends_with,omitempty"`
IsEmpty bool `json:"is_empty,omitempty"`
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type NumberFilterCondition struct {
Equals *float64 `json:"equals,omitempty"`
DoesNotEqual *float64 `json:"does_not_equal,omitempty"`
GreaterThan *float64 `json:"greater_than,omitempty"`
LessThan *float64 `json:"less_than,omitempty"`
GreaterThanOrEqualTo *float64 `json:"greater_than_or_equal_to,omitempty"`
LessThanOrEqualTo *float64 `json:"less_than_or_equal_to,omitempty"`
IsEmpty bool `json:"is_empty,omitempty"`
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type CheckboxFilterCondition struct {
Equals bool `json:"equals,omitempty"`
DoesNotEqual bool `json:"does_not_equal,omitempty"`
}
type SelectFilterCondition struct {
Equals string `json:"equals,omitempty"`
DoesNotEqual string `json:"does_not_equal,omitempty"`
IsEmpty bool `json:"is_empty,omitempty"`
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type MultiSelectFilterCondition struct {
Contains string `json:"contains,omitempty"`
DoesNotContain string `json:"does_not_contain,omitempty"`
IsEmpty bool `json:"is_empty,omitempty"`
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type DateFilterCondition struct {
Equals *Date `json:"equals,omitempty"`
Before *Date `json:"before,omitempty"`
After *Date `json:"after,omitempty"`
OnOrBefore *Date `json:"on_or_before,omitempty"`
OnOrAfter *Date `json:"on_or_after,omitempty"`
PastWeek *struct{} `json:"past_week,omitempty"`
PastMonth *struct{} `json:"past_month,omitempty"`
PastYear *struct{} `json:"past_year,omitempty"`
NextWeek *struct{} `json:"next_week,omitempty"`
NextMonth *struct{} `json:"next_month,omitempty"`
NextYear *struct{} `json:"next_year,omitempty"`
IsEmpty bool `json:"is_empty,omitempty"`
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type PeopleFilterCondition struct {
Contains string `json:"contains,omitempty"`
DoesNotContain string `json:"does_not_contain,omitempty"`
IsEmpty bool `json:"is_empty,omitempty"`
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type FilesFilterCondition struct {
IsEmpty bool `json:"is_empty,omitempty"`
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type RelationFilterCondition struct {
Contains string `json:"contains,omitempty"`
DoesNotContain string `json:"does_not_contain,omitempty"`
IsEmpty bool `json:"is_empty,omitempty"`
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type FormulaFilterCondition struct {
// DEPRECATED use `String` instead
Text *TextFilterCondition `json:"text,omitempty"`
String *TextFilterCondition `json:"string,omitempty"`
Checkbox *CheckboxFilterCondition `json:"checkbox,omitempty"`
Number *NumberFilterCondition `json:"number,omitempty"`
Date *DateFilterCondition `json:"date,omitempty"`
}
type RollupFilterCondition struct {
Any *RollupSubfilterCondition `json:"any,omitempty"`
None *RollupSubfilterCondition `json:"none,omitempty"`
Every *RollupSubfilterCondition `json:"every,omitempty"`
Date *DateFilterCondition `json:"date,omitempty"`
Number *NumberFilterCondition `json:"number,omitempty"`
}
type RollupSubfilterCondition struct {
RichText *TextFilterCondition `json:"rich_text,omitempty"`
Number *NumberFilterCondition `json:"number,omitempty"`
Checkbox *CheckboxFilterCondition `json:"checkbox,omitempty"`
Select *SelectFilterCondition `json:"select,omitempty"`
MultiSelect *MultiSelectFilterCondition `json:"multiSelect,omitempty"`
Relation *RelationFilterCondition `json:"relation,omitempty"`
Date *DateFilterCondition `json:"date,omitempty"`
People *PeopleFilterCondition `json:"people,omitempty"`
Files *FilesFilterCondition `json:"files,omitempty"`
}
type StatusFilterCondition struct {
Equals string `json:"equals,omitempty"`
DoesNotEqual string `json:"does_not_equal,omitempty"`
IsEmpty bool `json:"is_empty,omitempty"`
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type UniqueIdFilterCondition struct {
Equals *int `json:"equals,omitempty"`
DoesNotEqual *int `json:"does_not_equal,omitempty"`
GreaterThan *int `json:"greater_than,omitempty"`
LessThan *int `json:"less_than,omitempty"`
GreaterThanOrEqualTo *int `json:"greater_than_or_equal_to,omitempty"`
LessThanOrEqualTo *int `json:"less_than_or_equal_to,omitempty"`
}