Skip to content

Commit

Permalink
Merge pull request #106 from naitsirch/fix_request_filter
Browse files Browse the repository at this point in the history
Use query parameters in GET requests for filtering
  • Loading branch information
DumbergerL authored Sep 12, 2022
2 parents 114d4db + 1f3014c commit 907cb5b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Requests/PersonRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function whoami(): Person
public function get(): array
{
$options = [
"json" => []
"query" => []
];

//Where-Clauses
Expand Down
10 changes: 5 additions & 5 deletions src/Requests/Traits/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/Requests/Traits/WhereCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion tests/unit/HttpMock/HttpMockDataResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 907cb5b

Please sign in to comment.