2
2
3
3
namespace FiveamCode \LaravelNotionApi \Endpoints ;
4
4
5
-
5
+ use Illuminate \ Support \ Collection ;
6
6
use FiveamCode \LaravelNotionApi \Notion ;
7
- use \ FiveamCode \LaravelNotionApi \Entities \ Database as DatabaseEntity ;
7
+ use FiveamCode \LaravelNotionApi \Query \ Filter ;
8
8
use FiveamCode \LaravelNotionApi \Query \Sorting ;
9
- use Illuminate \Support \Collection ;
9
+ use FiveamCode \LaravelNotionApi \Query \StartCursor ;
10
+ use FiveamCode \LaravelNotionApi \Exceptions \WrapperException ;
10
11
11
12
class Database extends Endpoint
12
13
{
13
14
private string $ databaseId ;
14
- private Collection $ sortings ;
15
+
16
+ private Collection $ filter ;
17
+ private Collection $ sorts ;
18
+
19
+ private ?StartCursor $ startCursor = null ;
20
+ private ?int $ pageSize = null ;
21
+
15
22
16
23
public function __construct (string $ databaseId , Notion $ notion )
17
24
{
18
25
$ this ->databaseId = $ databaseId ;
26
+
27
+ $ this ->sorts = new Collection ();
28
+ $ this ->filter = new Collection ();
29
+
19
30
parent ::__construct ($ notion );
20
31
}
21
32
@@ -31,17 +42,21 @@ public function query(): array
31
42
} ' ;
32
43
33
44
34
- $ sortingJson = '{
35
- "property": "Ordered",
36
- "timestamp": "created_time",
37
- "direction": "descending"
38
- } ' ;
45
+ $ filter = json_decode ($ filterJson );
39
46
47
+ if ($ this ->sorts ->isNotEmpty ())
48
+ $ postData ["sorts " ] = Sorting::sortQuery ($ this ->sorts );
49
+
50
+ if ($ this ->filter ->isNotEmpty ())
51
+ $ postData ["filter " ] = []; //Filter::filterQuery($this->filter);
52
+
53
+ if ($ this ->startCursor !== null )
54
+ $ postData ["start_cursor " ] = $ this ->startCursor ;
55
+
56
+ if ($ this ->pageSize !== null )
57
+ $ postData ["page_size " ] = $ this ->pageSize ;
40
58
41
- $ filter = json_decode ($ filterJson );
42
59
43
- if ($ this ->sortings ->isNotEmpty ())
44
- $ postData ["sorts " ] = Sorting::sortQuery ($ this ->sortings );
45
60
46
61
$ response = $ this ->post (
47
62
$ this ->url (Endpoint::DATABASES . "/ {$ this ->databaseId }/query " ),
@@ -61,20 +76,24 @@ public function filterBy()
61
76
62
77
public function sortBy (Collection $ sortings )
63
78
{
64
- $ this ->sortings = $ sortings ;
79
+ $ this ->sorts = $ sortings ;
65
80
66
81
return $ this ;
67
82
}
68
83
69
- public function limit ()
84
+ public function limit (int $ limit )
70
85
{
86
+ $ this ->pageSize = min ($ limit , 100 );
71
87
72
88
return $ this ;
73
89
}
74
90
75
- public function offset ()
91
+ public function offset (StartCursor $ startCursor )
76
92
{
93
+ // toDo
94
+ throw WrapperException::instance ("Not implemented yet. " );
77
95
96
+ $ this ->startCursor = $ startCursor ;
78
97
return $ this ;
79
98
}
80
99
}
0 commit comments