Skip to content

Commit 7c35d07

Browse files
committed
pagination client can be sorted (expect contact)
1 parent b1c11ae commit 7c35d07

9 files changed

+27
-24
lines changed

README.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,18 @@ $api = new \Sysix\LexOffice\Api($apiKey, $httpClient);
5555
### Contact Endpoint
5656
```php
5757

58-
// get a page
5958
/** @var \Sysix\LexOffice\Api $api */
6059
$client = $api->contact();
6160

6261
// filters
6362
$client->size = 100;
64-
$client->sortDirection = 'ASC';
65-
$client->sortProperty = 'name';
6663
$client->number = 123456;
6764
$client->customer = true;
6865
$client->vendor = false;
6966

7067
// get a page
7168
$response = $client->getPage(0);
7269

73-
7470
// other methods
7571
$response = $client->get($entityId);
7672
$response = $client->create($data);
@@ -162,16 +158,18 @@ $response = $api->profile()->get();
162158
### Recurring Templates Endpoint
163159
```php
164160

165-
// get single entitiy
166-
$response = $api->recurringTemplate()->get($entityId);
167-
168-
// use pagination
169161
$client = $api->recurringTemplate();
170-
$client->size = 100;
171162

163+
// filters
164+
$client->size = 100;
165+
$client->sortDirection = 'DESC';
166+
$client->sortColumn = 'updatedDate';
172167

173168
// get a page
174169
$response = $client->getPage(0);
170+
171+
// other methods
172+
$response = $api->recurringTemplate()->get($entityId);
175173
```
176174

177175

src/Clients/Contact.php

-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ class Contact extends PaginationClient
1515

1616
protected string $resource = 'contacts';
1717

18-
public string $sortDirection = 'ASC';
19-
20-
public string $sortProperty = 'name';
2118

2219
public ?int $number = null;
2320

@@ -27,8 +24,6 @@ class Contact extends PaginationClient
2724

2825
protected function buildQueryParams(array $params): string
2926
{
30-
$params['direction'] = $this->sortDirection;
31-
$params['property'] = $this->sortProperty;
3227
$params['number'] = $this->number;
3328
$params['customer'] = $this->customer;
3429
$params['vendor'] = $this->vendor;

src/Clients/RecurringTemplate.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ class RecurringTemplate extends PaginationClient
1010
use GetTrait;
1111

1212
protected string $resource = 'recurring-templates';
13+
14+
public string $sortColumn = 'updatedDate';
1315
}

src/Clients/Traits/DocumentClientTrait.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ trait DocumentClientTrait
1111
{
1212
public function document(string $id, bool $asContent = false): ResponseInterface
1313
{
14-
$response = $this->api->newRequest('GET', $this->resource . '/' . rawurlencode($id) . '/document')
14+
$response = $this->api
15+
->newRequest('GET', $this->resource . '/' . rawurlencode($id) . '/document')
1516
->getResponse();
1617

1718
if ($asContent === false) {

src/Clients/VoucherList.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ class VoucherList extends PaginationClient
1010
protected string $resource = 'voucherlist';
1111

1212
public string $sortColumn = 'voucherNumber';
13-
public string $sortDirection = 'DESC';
1413

1514
/** @var string[] $types */
16-
public array $types = [];
15+
public array $types;
1716

1817
/** @var string[] $statuses */
19-
public array $statuses = [];
18+
public array $statuses;
2019

2120
public ?bool $archived = null;
2221

@@ -71,7 +70,6 @@ protected function buildQueryParams(array $params): string
7170
{
7271
$dateFormat = DateTimeInterface::ATOM;
7372

74-
$params['sort'] = $this->sortColumn . ',' . $this->sortDirection;
7573
$params['voucherType'] = implode(',', $this->types);
7674
$params['voucherStatus'] = implode(',', $this->statuses);
7775
$params['archived'] = $this->archived;

src/PaginationClient.php

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ abstract class PaginationClient extends BaseClient
99
{
1010
public int $size = 100;
1111

12+
public string $sortColumn;
13+
14+
public string $sortDirection = 'DESC';
15+
1216
protected function generatePageUrl(int $page): string
1317
{
1418
return $this->resource . '?' . $this->buildQueryParams([
@@ -23,6 +27,11 @@ protected function buildQueryParams(array $params): string
2327
{
2428
$params['size'] = $this->size;
2529

30+
// contact endpoint can't be sorted but is a Pagination client
31+
if (isset($this->sortColumn)) {
32+
$params['sort'] = $this->sortColumn . ',' . $this->sortDirection;
33+
}
34+
2635
return http_build_query($params);
2736
}
2837

tests/Clients/ContactTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testGetPage(): void
1818

1919
$this->assertEquals('GET', $api->request->getMethod());
2020
$this->assertEquals(
21-
$api->apiUrl . '/v1/contacts?page=0&direction=ASC&property=name&size=100',
21+
$api->apiUrl . '/v1/contacts?page=0&size=100',
2222
$api->request->getUri()->__toString()
2323
);
2424
}
@@ -34,7 +34,7 @@ public function testGetPageWithFilters(): void
3434
$client->getPage(0);
3535

3636
$this->assertEquals(
37-
$api->apiUrl . '/v1/contacts?page=0&direction=ASC&property=name&number=12345&customer=1&vendor=0&size=100',
37+
$api->apiUrl . '/v1/contacts?page=0&number=12345&customer=1&vendor=0&size=100',
3838
$api->request->getUri()->__toString()
3939
);
4040
}

tests/Clients/RecurringTemplateTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testGetPage(): void
3131

3232
$this->assertEquals('GET', $api->request->getMethod());
3333
$this->assertEquals(
34-
$api->apiUrl . '/v1/recurring-templates?page=0&size=100',
34+
$api->apiUrl . '/v1/recurring-templates?page=0&size=100&sort=updatedDate%2CDESC',
3535
$api->request->getUri()->__toString()
3636
);
3737
}

tests/Clients/VoucherListTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testGetPage(): void
2424

2525
$this->assertEquals('GET', $api->request->getMethod());
2626
$this->assertEquals(
27-
$api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100',
27+
$api->apiUrl . '/v1/voucherlist?page=0&voucherType=invoice&voucherStatus=open&archived=1&size=100&sort=voucherNumber%2CDESC',
2828
$api->request->getUri()->__toString()
2929
);
3030
}
@@ -48,7 +48,7 @@ public function testGetAll(): void
4848

4949
$this->assertEquals('GET', $api->request->getMethod());
5050
$this->assertEquals(
51-
$api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100',
51+
$api->apiUrl . '/v1/voucherlist?page=0&voucherType=invoice&voucherStatus=open&archived=1&size=100&sort=voucherNumber%2CDESC',
5252
$api->request->getUri()->__toString()
5353
);
5454
}

0 commit comments

Comments
 (0)