From e435e1a086700b8d7f36a5f4e63677b8accfc054 Mon Sep 17 00:00:00 2001 From: Thomas Merkel Date: Fri, 12 Apr 2024 20:48:09 +0200 Subject: [PATCH 1/2] Add new contact filters for email and name It should be possible to filter by email address or / and name as described in the API. References: - https://developers.lexoffice.io/docs/#contacts-endpoint-purpose --- README.md | 4 +++- src/Clients/Contact.php | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index caf433e..febb85a 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ $client = $api->contact(); // filters $client->size = 100; +$client->email = 'john.doe@example.com'; +$client->name = 'John Doe'; $client->number = 123456; $client->customer = true; $client->vendor = false; @@ -279,4 +281,4 @@ $response = $client->getPage(0); // can be possible null because the response body can be empty $json = \Sysix\LexOffice\Utils::getJsonFromResponse($response); // as object $json = \Sysix\LexOffice\Utils::getJsonFromResponse($response, true); // as associative array -``` \ No newline at end of file +``` diff --git a/src/Clients/Contact.php b/src/Clients/Contact.php index 94840d5..3ccec21 100644 --- a/src/Clients/Contact.php +++ b/src/Clients/Contact.php @@ -17,6 +17,10 @@ class Contact extends PaginationClient protected string $resource = 'contacts'; + public ?string $email = null; + + public ?string $name = null; + public ?int $number = null; public ?bool $customer = null; @@ -25,6 +29,8 @@ class Contact extends PaginationClient protected function buildQueryParams(array $params): string { + $params['email'] = $this->email; + $params['name'] = $this->name; $params['number'] = $this->number; $params['customer'] = $this->customer; $params['vendor'] = $this->vendor; From 1c073d3a0cf593da1dffc2dbee4c91342695d574 Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 13 Apr 2024 17:44:07 +0200 Subject: [PATCH 2/2] add tests for new contact filters --- tests/Clients/ContactTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Clients/ContactTest.php b/tests/Clients/ContactTest.php index c9fc7c6..48bf574 100644 --- a/tests/Clients/ContactTest.php +++ b/tests/Clients/ContactTest.php @@ -29,6 +29,8 @@ public function testGetPageWithFilters(): void { [$api, $client] = $this->createClientMockObject(Contact::class); + $client->email = 'john.doe@example.com'; + $client->name = 'John Doe'; $client->number = 12345; $client->customer = true; $client->vendor = false; @@ -36,7 +38,7 @@ public function testGetPageWithFilters(): void $client->getPage(0); $this->assertEquals( - $api->apiUrl . '/v1/contacts?page=0&number=12345&customer=1&vendor=0&size=100', + $api->apiUrl . '/v1/contacts?page=0&email=john.doe%40example.com&name=John+Doe&number=12345&customer=1&vendor=0&size=100', $api->getRequest()->getUri()->__toString() ); }