From 98e79357efaa5d667b6c65f3fe7db467e4ca9901 Mon Sep 17 00:00:00 2001 From: naitsirch Date: Sat, 10 Sep 2022 01:40:37 +0200 Subject: [PATCH 1/2] Use query parameters in GET requests for filtering currently this is done with json/body params. It is working, because guzzle magically turns body params into query params when doing GET requests, but this is not clean and we should not rely on this behaviour. --- src/Requests/PersonRequestBuilder.php | 2 +- src/Requests/Traits/Pagination.php | 10 +++++----- src/Requests/Traits/WhereCondition.php | 6 +++--- tests/unit/HttpMock/HttpMockDataResolver.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Requests/PersonRequestBuilder.php b/src/Requests/PersonRequestBuilder.php index 93b08525..a4f43592 100644 --- a/src/Requests/PersonRequestBuilder.php +++ b/src/Requests/PersonRequestBuilder.php @@ -21,7 +21,7 @@ public function whoami(): Person public function get(): array { $options = [ - "json" => [] + "query" => [] ]; //Where-Clauses diff --git a/src/Requests/Traits/Pagination.php b/src/Requests/Traits/Pagination.php index 185eaa05..9c621f60 100644 --- a/src/Requests/Traits/Pagination.php +++ b/src/Requests/Traits/Pagination.php @@ -13,14 +13,14 @@ protected function collectDataFromPages(string $url, array $options = []): array $client = CTClient::getClient(); $collectedData = []; - if (isset($options["json"]["page"])) { + if (isset($options["query"]["page"])) { $manualPagination = true; } else { // Add Page Information to Options - if (!array_key_exists("json", $options)) { - $options["json"] = []; + if (!array_key_exists("query", $options)) { + $options["query"] = []; } - $options["json"]["page"] = 1; + $options["query"]["page"] = 1; $manualPagination = false; } @@ -37,7 +37,7 @@ protected function collectDataFromPages(string $url, array $options = []): array // Collect Date from Second till Last page for ($i = 2; $i <= $lastPage; $i++) { - $options["json"]["page"] = $i; + $options["query"]["page"] = $i; $response = $client->get($url, $options); diff --git a/src/Requests/Traits/WhereCondition.php b/src/Requests/Traits/WhereCondition.php index 0d13e954..e38c9366 100644 --- a/src/Requests/Traits/WhereCondition.php +++ b/src/Requests/Traits/WhereCondition.php @@ -21,12 +21,12 @@ public function where(string $key, $value): self protected function addWhereConditionsToOption(&$options): void { - if (!array_key_exists("json", $options)) { - $options["json"] = []; + if (!array_key_exists("query", $options)) { + $options["query"] = []; } foreach ($this->whereCriteria as $whereKey => $whereValue) { - $options["json"][$whereKey] = $whereValue; + $options["query"][$whereKey] = $whereValue; } } } \ No newline at end of file diff --git a/tests/unit/HttpMock/HttpMockDataResolver.php b/tests/unit/HttpMock/HttpMockDataResolver.php index 767ba8f2..be4db1dd 100644 --- a/tests/unit/HttpMock/HttpMockDataResolver.php +++ b/tests/unit/HttpMock/HttpMockDataResolver.php @@ -39,7 +39,7 @@ private static function convertEndpointToFileName(string $endpoint, array $optio // convert string to lowercase $endpoint = strtolower($endpoint); - $pageNr = CTUtil::arrayPathGet($options, "json.page"); + $pageNr = CTUtil::arrayPathGet($options, "query.page"); if (!is_null($pageNr) && $pageNr > 1) { $endpoint .= "_page_" . $pageNr; CTLog::getLog()->debug("Append Page-Number to Endpoint-Filename: " . $endpoint); From 1f3014c61fd2708c2f15cdb4f1c1565dd05d6b95 Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Mon, 12 Sep 2022 07:14:01 +0200 Subject: [PATCH 2/2] docs(CHANGELOG): add changelog for pr --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37f62a35..24e3ab4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [Status-Code handling and Exception-handling](https://github.com/5pm-HDH/churchtools-api/pull/99) - [Refactor delete person](https://github.com/5pm-HDH/churchtools-api/pull/100) - [Refactor FillWithData](https://github.com/5pm-HDH/churchtools-api/pull/101) +- [Refactor: Use Query-Parameters for Where-Clause](https://github.com/5pm-HDH/churchtools-api/pull/106) ### Fixed