Skip to content

Commit 3b79e2b

Browse files
committed
added limit to database endpoint and prepared
start cursor structure (NOT implemented yet)
1 parent 3ab0d96 commit 3b79e2b

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

src/Endpoints/Database.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@
22

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5-
5+
use Illuminate\Support\Collection;
66
use FiveamCode\LaravelNotionApi\Notion;
7-
use \FiveamCode\LaravelNotionApi\Entities\Database as DatabaseEntity;
7+
use FiveamCode\LaravelNotionApi\Query\Filter;
88
use FiveamCode\LaravelNotionApi\Query\Sorting;
9-
use Illuminate\Support\Collection;
9+
use FiveamCode\LaravelNotionApi\Query\StartCursor;
10+
use FiveamCode\LaravelNotionApi\Exceptions\WrapperException;
1011

1112
class 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
}

src/Query/Sorting.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public function __construct(string $direction, string $property = null, string $
3333

3434
public static function timestampSort(string $timestampToSort, string $direction)
3535
{
36-
3736
$propertySort = new Sorting($direction, null, $timestampToSort);
3837

3938
return $propertySort;

src/Query/StartCursor.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace FiveamCode\LaravelNotionApi\Query;
4+
5+
use FiveamCode\LaravelNotionApi\Exceptions\WrapperException;
6+
use Illuminate\Support\Collection;
7+
8+
class StartCursor {
9+
private string $cursor;
10+
11+
public function __construct(string $cursor)
12+
{
13+
$this->cursor = $cursor;
14+
}
15+
}

0 commit comments

Comments
 (0)