22
33namespace FiveamCode \LaravelNotionApi \Endpoints ;
44
5-
5+ use Illuminate \ Support \ Collection ;
66use FiveamCode \LaravelNotionApi \Notion ;
7- use \ FiveamCode \LaravelNotionApi \Entities \ Database as DatabaseEntity ;
7+ use FiveamCode \LaravelNotionApi \Query \ Filter ;
88use FiveamCode \LaravelNotionApi \Query \Sorting ;
9- use Illuminate \Support \Collection ;
9+ use FiveamCode \LaravelNotionApi \Query \StartCursor ;
10+ use FiveamCode \LaravelNotionApi \Exceptions \WrapperException ;
1011
1112class Database extends Endpoint
1213{
1314 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+
1522
1623 public function __construct (string $ databaseId , Notion $ notion )
1724 {
1825 $ this ->databaseId = $ databaseId ;
26+
27+ $ this ->sorts = new Collection ();
28+ $ this ->filter = new Collection ();
29+
1930 parent ::__construct ($ notion );
2031 }
2132
@@ -31,17 +42,21 @@ public function query(): array
3142 } ' ;
3243
3344
34- $ sortingJson = '{
35- "property": "Ordered",
36- "timestamp": "created_time",
37- "direction": "descending"
38- } ' ;
45+ $ filter = json_decode ($ filterJson );
3946
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 ;
4058
41- $ filter = json_decode ($ filterJson );
4259
43- if ($ this ->sortings ->isNotEmpty ())
44- $ postData ["sorts " ] = Sorting::sortQuery ($ this ->sortings );
4560
4661 $ response = $ this ->post (
4762 $ this ->url (Endpoint::DATABASES . "/ {$ this ->databaseId }/query " ),
@@ -61,20 +76,24 @@ public function filterBy()
6176
6277 public function sortBy (Collection $ sortings )
6378 {
64- $ this ->sortings = $ sortings ;
79+ $ this ->sorts = $ sortings ;
6580
6681 return $ this ;
6782 }
6883
69- public function limit ()
84+ public function limit (int $ limit )
7085 {
86+ $ this ->pageSize = min ($ limit , 100 );
7187
7288 return $ this ;
7389 }
7490
75- public function offset ()
91+ public function offset (StartCursor $ startCursor )
7692 {
93+ // toDo
94+ throw WrapperException::instance ("Not implemented yet. " );
7795
96+ $ this ->startCursor = $ startCursor ;
7897 return $ this ;
7998 }
8099}
0 commit comments