Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 00e71bd

Browse files
Merge pull request #19 from asevos/main
Correct filter models 🐛
2 parents 2c55155 + 128b22c commit 00e71bd

File tree

15 files changed

+799
-212
lines changed

15 files changed

+799
-212
lines changed

‎README.md‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,54 @@
1313
## Installation
1414

1515
.Net CLI
16+
1617
```
1718
dotnet add package Notion.Net
1819
```
1920

2021
## Usage
2122

2223
> Before getting started, you need to [create an integration](https://www.notion.com/my-integrations) and find the token. You can learn more about authorization [here](https://developers.notion.com/docs/authorization).
23-
24+
2425
Import and initialize the client using the integration token created above.
25-
26+
2627
![image](https://user-images.githubusercontent.com/18693839/119268863-79925b00-bc12-11eb-92cb-d5a9a8c57fdc.png)
2728

2829
Make A request to any Endpoint. For example you can call below to fetch the paginated list of users.
29-
30+
3031
![image](https://user-images.githubusercontent.com/18693839/119268924-ae9ead80-bc12-11eb-9d1a-925267896d9e.png)
3132

33+
### Querying a database
34+
35+
After you initialized your client and got an id of a database, you can query it for any contained pages. You can add filters and sorts to your request. Here is a simple example:
36+
37+
```C#
38+
// Date filter for page property called "When"
39+
var dateFilter = new DateFilter("When", onOrAfter: DateTime.Now);
40+
41+
var queryParams = new DatabasesQueryParameters { Filter = dateFilter };
42+
var pages = await client.Databases.QueryAsync(databaseId, queryParams);
43+
```
3244

45+
Filters constructors contain all possible filter conditions, but you need to choose only condition per filter, all other should be `null`. So, for example this code would not filter by 2 conditions as one might expect:
46+
47+
```C#
48+
var filter = new TextFilter("Name", startsWith: "Mr", contains: "John"); // WRONG FILTER USAGE
49+
50+
```
51+
52+
To use complex filters, use class `CompoundFilter`. It allows adding many filters and even nesting compound filters into each other (it works as filter group in Notion interface). Here is an example of filter that would return pages that were due in past month AND either had a certain assignee OR had high urgency:
53+
54+
```C#
55+
var selectFilter = new SelectFilter("Urgency", equal: "High");
56+
var assigneeFilter = new PeopleFilter("Assignee", contains: "some-uuid");
57+
var dateFilter = new DateFilter("Due", pastMonth: new Dictionary<string, object>());
58+
59+
var orGroup = new List<Filter> { assigneeFilter, selectFilter };
60+
var complexFiler = new CompoundFilter(
61+
and: new List<Filter> { dateFilter, new CompoundFilter(or: orGroup) }
62+
);
63+
```
3364

3465
## Contribution Guideline
3566

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

Lines changed: 0 additions & 208 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class CheckboxFilter : SinglePropertyFilter
7+
{
8+
public Condition Checkbox { get; set; }
9+
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+
19+
public class Condition
20+
{
21+
[JsonProperty("equals")]
22+
public bool? Equal { get; set; }
23+
24+
[JsonProperty("does_not_equal")]
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+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /