Skip to content

Commit f23b595

Browse files
committed
✨ Adds filter constructors
1 parent 9c9028e commit f23b595

File tree

12 files changed

+382
-139
lines changed

12 files changed

+382
-139
lines changed

Src/Notion.Client/Models/Filters/Checkbox.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,28 @@ public class CheckboxFilter : SinglePropertyFilter
77
{
88
public Condition Checkbox { get; set; }
99

10+
public CheckboxFilter(
11+
string propertyName,
12+
bool? equal = null,
13+
bool? doesNotEqual = null)
14+
{
15+
Property = propertyName;
16+
Checkbox = new Condition(equal: equal, doesNotEqual: doesNotEqual);
17+
}
18+
1019
public class Condition
1120
{
1221
[JsonProperty("equals")]
13-
public Nullable<bool> Equal { get; set; }
22+
public bool? Equal { get; set; }
1423

1524
[JsonProperty("does_not_equal")]
16-
public Nullable<bool> DoesNotEqual { get; set; }
25+
public bool? DoesNotEqual { get; set; }
26+
27+
public Condition(Nullable<bool> equal = null, Nullable<bool> doesNotEqual = null)
28+
{
29+
Equal = equal;
30+
DoesNotEqual = doesNotEqual;
31+
}
1732
}
1833
}
1934
}

Src/Notion.Client/Models/Filters/Date.cs

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,61 @@ public class DateFilter : SinglePropertyFilter
99
{
1010
public Condition Date { get; set; }
1111

12+
public DateFilter(
13+
string propertyName,
14+
DateTime? equal = null,
15+
DateTime? before = null,
16+
DateTime? after = null,
17+
DateTime? onOrBefore = null,
18+
DateTime? onOrAfter = null,
19+
Dictionary<string, object> pastWeek = null,
20+
Dictionary<string, object> pastMonth = null,
21+
Dictionary<string, object> pastYear = null,
22+
Dictionary<string, object> nextWeek = null,
23+
Dictionary<string, object> nextMonth = null,
24+
Dictionary<string, object> nextYear = null,
25+
bool? isEmpty = null,
26+
bool? isNotEmpty = null)
27+
{
28+
Property = propertyName;
29+
Date = new Condition(
30+
equal: equal,
31+
before: before,
32+
after: after,
33+
onOrBefore: onOrBefore,
34+
onOrAfter: onOrAfter,
35+
pastWeek: pastWeek,
36+
pastMonth: pastMonth,
37+
pastYear: pastYear,
38+
nextWeek: nextWeek,
39+
nextMonth: nextMonth,
40+
nextYear: nextYear,
41+
isEmpty: isEmpty,
42+
isNotEmpty: isNotEmpty
43+
);
44+
}
45+
1246
public class Condition
1347
{
1448
[JsonProperty("equals")]
1549
[JsonConverter(typeof(IsoDateTimeConverter))]
16-
public Nullable<DateTime> Equal { get; set; }
50+
public DateTime? Equal { get; set; }
1751

1852
[JsonProperty("before")]
1953
[JsonConverter(typeof(IsoDateTimeConverter))]
20-
public Nullable<DateTime> Before { get; set; }
54+
public DateTime? Before { get; set; }
2155

2256
[JsonProperty("after")]
2357
[JsonConverter(typeof(IsoDateTimeConverter))]
24-
public Nullable<DateTime> After { get; set; }
58+
public DateTime? After { get; set; }
2559

2660
[JsonProperty("on_or_before")]
2761
[JsonConverter(typeof(IsoDateTimeConverter))]
28-
public Nullable<DateTime> OnOrBefore { get; set; }
62+
public DateTime? OnOrBefore { get; set; }
2963

3064
[JsonProperty("on_or_after")]
3165
[JsonConverter(typeof(IsoDateTimeConverter))]
32-
public Nullable<DateTime> OnOrAfter { get; set; }
66+
public DateTime? OnOrAfter { get; set; }
3367

3468
[JsonProperty("past_week")]
3569
public Dictionary<string, object> PastWeek { get; set; }
@@ -50,10 +84,40 @@ public class Condition
5084
public Dictionary<string, object> NextYear { get; set; }
5185

5286
[JsonProperty("is_empty")]
53-
public Nullable<bool> IsEmpty { get; set; }
87+
public bool? IsEmpty { get; set; }
5488

5589
[JsonProperty("is_not_empty")]
56-
public Nullable<bool> IsNotEmpty { get; set; }
90+
public bool? IsNotEmpty { get; set; }
91+
92+
public Condition(
93+
DateTime? equal = null,
94+
DateTime? before = null,
95+
DateTime? after = null,
96+
DateTime? onOrBefore = null,
97+
DateTime? onOrAfter = null,
98+
Dictionary<string, object> pastWeek = null,
99+
Dictionary<string, object> pastMonth = null,
100+
Dictionary<string, object> pastYear = null,
101+
Dictionary<string, object> nextWeek = null,
102+
Dictionary<string, object> nextMonth = null,
103+
Dictionary<string, object> nextYear = null,
104+
bool? isEmpty = null,
105+
bool? isNotEmpty = null)
106+
{
107+
Equal = equal;
108+
Before = before;
109+
After = after;
110+
OnOrBefore = onOrBefore;
111+
OnOrAfter = onOrAfter;
112+
PastWeek = pastWeek;
113+
PastMonth = pastMonth;
114+
PastYear = pastYear;
115+
NextWeek = nextWeek;
116+
NextMonth = nextMonth;
117+
NextYear = nextYear;
118+
IsEmpty = isEmpty;
119+
IsNotEmpty = isNotEmpty;
120+
}
57121
}
58122
}
59123
}

Src/Notion.Client/Models/Filters/Files.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,30 @@ public class FilesFilter : SinglePropertyFilter
88
{
99
public Condition Files { get; set; }
1010

11+
public FilesFilter(
12+
string propertyName,
13+
bool? isEmpty = null,
14+
bool? isNotEmpty = null)
15+
{
16+
Property = propertyName;
17+
Files = new Condition(isEmpty: isEmpty, isNotEmpty: isNotEmpty);
18+
}
19+
1120
public class Condition
1221
{
1322
[JsonProperty("is_empty")]
14-
public Nullable<bool> IsEmpty { get; set; }
23+
public bool? IsEmpty { get; set; }
1524

1625
[JsonProperty("is_not_empty")]
17-
public Nullable<bool> IsNotEmpty { get; set; }
26+
public bool? IsNotEmpty { get; set; }
27+
28+
public Condition(
29+
bool? isEmpty = null,
30+
bool? isNotEmpty = null)
31+
{
32+
IsEmpty = isEmpty;
33+
IsNotEmpty = isNotEmpty;
34+
}
1835
}
1936
}
2037
}

Src/Notion.Client/Models/Filters/Filter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ public class CompoundFilter : Filter
1616
{
1717
public List<Filter> Or { get; set; }
1818
public List<Filter> And { get; set; }
19+
20+
public CompoundFilter(List<Filter> or = null, List<Filter> and = null)
21+
{
22+
Or = or;
23+
And = and;
24+
}
1925
}
2026
}

Src/Notion.Client/Models/Filters/Formula.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,40 @@ public class FormulaFilter : SinglePropertyFilter
44
{
55
public Condition Formula { get; set; }
66

7+
public FormulaFilter(
8+
string propertyName,
9+
TextFilter.Condition text = null,
10+
CheckboxFilter.Condition checkbox = null,
11+
NumberFilter.Condition number = null,
12+
DateFilter.Condition date = null)
13+
{
14+
Property = propertyName;
15+
Formula = new Condition(
16+
text: text,
17+
checkbox: checkbox,
18+
number: number,
19+
date: date
20+
);
21+
}
22+
723
public class Condition
824
{
925
public TextFilter.Condition Text { get; set; }
1026
public CheckboxFilter.Condition Checkbox { get; set; }
1127
public NumberFilter.Condition Number { get; set; }
1228
public DateFilter.Condition Date { get; set; }
29+
30+
public Condition(
31+
TextFilter.Condition text = null,
32+
CheckboxFilter.Condition checkbox = null,
33+
NumberFilter.Condition number = null,
34+
DateFilter.Condition date = null)
35+
{
36+
Text = text;
37+
Checkbox = checkbox;
38+
Number = number;
39+
Date = date;
40+
}
1341
}
1442
}
1543
}

Src/Notion.Client/Models/Filters/Multiselect.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ public class MultiSelectFilter : SinglePropertyFilter
88
[JsonProperty("multi_select")]
99
public Condition MultiSelect { get; set; }
1010

11+
public MultiSelectFilter(
12+
string propertyName,
13+
string contains = null,
14+
string doesNotContain = null,
15+
bool? isEmpty = null,
16+
bool? isNotEmpty = null)
17+
{
18+
Property = propertyName;
19+
MultiSelect = new Condition(
20+
contains: contains,
21+
doesNotContain: doesNotContain,
22+
isEmpty: isEmpty,
23+
isNotEmpty: isNotEmpty
24+
);
25+
}
26+
27+
1128
public class Condition
1229
{
1330
public string Contains { get; set; }
@@ -16,10 +33,23 @@ public class Condition
1633
public string DoesNotContain { get; set; }
1734

1835
[JsonProperty("is_empty")]
19-
public Nullable<bool> IsEmpty { get; set; }
36+
public bool? IsEmpty { get; set; }
2037

2138
[JsonProperty("is_not_empty")]
22-
public Nullable<bool> IsNotEmpty { get; set; }
39+
public bool? IsNotEmpty { get; set; }
40+
41+
public Condition(
42+
string contains = null,
43+
string doesNotContain = null,
44+
bool? isEmpty = null,
45+
bool? isNotEmpty = null)
46+
{
47+
Contains = contains;
48+
DoesNotContain = doesNotContain;
49+
IsEmpty = isEmpty;
50+
IsNotEmpty = isNotEmpty;
51+
}
2352
}
53+
2454
}
2555
}

Src/Notion.Client/Models/Filters/Number.cs

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,76 @@ public class NumberFilter : SinglePropertyFilter
77
{
88
public Condition Number { get; set; }
99

10+
public NumberFilter(
11+
string propertyName,
12+
double? equal = null,
13+
double? doesNotEqual = null,
14+
double? greaterThan = null,
15+
double? lessThan = null,
16+
double? greaterThanOrEqualTo = null,
17+
double? lessThanOrEqualTo = null,
18+
bool? isEmpty = null,
19+
bool? isNotEmpty = null)
20+
{
21+
Property = propertyName;
22+
Number = new Condition(
23+
equal: equal,
24+
doesNotEqual: doesNotEqual,
25+
greaterThan: greaterThan,
26+
lessThan: lessThan,
27+
greaterThanOrEqualTo: greaterThanOrEqualTo,
28+
lessThanOrEqualTo: lessThanOrEqualTo,
29+
isEmpty: isEmpty,
30+
isNotEmpty: isNotEmpty
31+
);
32+
}
33+
1034
public class Condition
1135
{
1236
[JsonProperty("equals")]
13-
public Nullable<double> Equal { get; set; }
37+
public double? Equal { get; set; }
1438

1539
[JsonProperty("does_not_equal")]
16-
public Nullable<double> DoesNotEqual { get; set; }
40+
public double? DoesNotEqual { get; set; }
1741

1842
[JsonProperty("greater_than")]
19-
public Nullable<double> GreaterThan { get; set; }
43+
public double? GreaterThan { get; set; }
2044

2145
[JsonProperty("less_than")]
22-
public Nullable<double> LessThan { get; set; }
46+
public double? LessThan { get; set; }
2347

2448
[JsonProperty("greater_than_or_equal_to")]
25-
public Nullable<double> GreaterThanOrEqualTo { get; set; }
49+
public double? GreaterThanOrEqualTo { get; set; }
2650

2751
[JsonProperty("less_than_or_equal_to")]
28-
public Nullable<double> LessThanOrEqualTo { get; set; }
52+
public double? LessThanOrEqualTo { get; set; }
2953

3054
[JsonProperty("is_empty")]
31-
public Nullable<bool> IsEmpty { get; set; }
55+
public bool? IsEmpty { get; set; }
3256

3357
[JsonProperty("is_not_empty")]
34-
public Nullable<bool> IsNotEmpty { get; set; }
58+
public bool? IsNotEmpty { get; set; }
59+
60+
public Condition(
61+
double? equal = null,
62+
double? doesNotEqual = null,
63+
double? greaterThan = null,
64+
double? lessThan = null,
65+
double? greaterThanOrEqualTo = null,
66+
double? lessThanOrEqualTo = null,
67+
bool? isEmpty = null,
68+
bool? isNotEmpty = null)
69+
{
70+
Equal = equal;
71+
DoesNotEqual = doesNotEqual;
72+
GreaterThan = greaterThan;
73+
LessThan = lessThan;
74+
GreaterThanOrEqualTo = greaterThanOrEqualTo;
75+
LessThanOrEqualTo = lessThanOrEqualTo;
76+
IsEmpty = isEmpty;
77+
IsNotEmpty = isNotEmpty;
78+
}
3579
}
80+
3681
}
3782
}

0 commit comments

Comments
 (0)