Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
III-2081: Grab multiple region ids from search parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
bramcordie committed May 16, 2017
1 parent a703551 commit b9b18ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"cultuurnet/hydra": "~0.1",
"cultuurnet/udb3-search": "~0.1",
"cultuurnet/udb3-search": "dev-feature/III-2081 as 0.1",
"cultuurnet/geocoding": "~0.1",
"cultuurnet/valueobjects": "~3.0",
"symfony/http-foundation": "~2.7.2"
Expand Down
23 changes: 20 additions & 3 deletions src/OfferSearchController.php
Expand Up @@ -176,11 +176,12 @@ public function search(Request $request)
);
}

if (!empty($request->query->get('regionId'))) {
$regionIds = $this->getRegionIdsFromQuery($request, 'regions');
if (!empty($regionIds)) {
$parameters = $parameters->withRegion(
new RegionId($request->query->get('regionId')),
$this->regionIndexName,
$this->regionDocumentType
$this->regionDocumentType,
...$regionIds
);
}

Expand Down Expand Up @@ -509,6 +510,22 @@ function ($value) {
);
}

/**
* @param Request $request
* @param string $queryParameter
* @return RegionIds[]
*/
private function getRegionIdsFromQuery(Request $request, $queryParameter)
{
return $this->getArrayFromQueryParameters(
$request,
$queryParameter,
function ($value) {
return new RegionId($value);
}
);
}

/**
* @param Request $request
* @param string $queryParameter
Expand Down
7 changes: 4 additions & 3 deletions tests/OfferSearchControllerTest.php
Expand Up @@ -113,7 +113,7 @@ public function it_returns_a_paged_collection_of_search_results_based_on_request
'availableFrom' => '2017-04-26T00:00:00+01:00',
'availableTo' => '2017-04-28T15:30:23+01:00',
'workflowStatus' => 'DRAFT',
'regionId' => 'gem-leuven',
'regions' => ['gem-leuven', 'prv-limburg'],
'coordinates' => '-40,70',
'distance' => '30km',
'postalCode' => 3000,
Expand Down Expand Up @@ -172,9 +172,10 @@ public function it_returns_a_paged_collection_of_search_results_based_on_request
new WorkflowStatus('DRAFT')
)
->withRegion(
new RegionId('gem-leuven'),
$this->regionIndexName,
$this->regionDocumentType
$this->regionDocumentType,
new RegionId('gem-leuven'),
new RegionId('prv-limburg')
)
->withGeoDistanceParameters(
new GeoDistanceParameters(
Expand Down

0 comments on commit b9b18ca

Please sign in to comment.