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

Commit

Permalink
III-1958: Add q search parameter for offers
Browse files Browse the repository at this point in the history
  • Loading branch information
bertramakers committed Mar 9, 2017
1 parent 5248302 commit aa4bad9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"cultuurnet/hydra": "~0.1",
"cultuurnet/udb3-search": "dev-feature/III-1779 as 0.1",
"cultuurnet/udb3-search": "dev-feature/III-1958 as 0.1",
"nicolopignatelli/valueobjects": "~3.0",
"symfony/http-foundation": "~2.7.2"
},
Expand Down
12 changes: 12 additions & 0 deletions src/OfferSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use CultuurNet\UDB3\Search\Offer\OfferSearchParameters;
use CultuurNet\UDB3\Search\Offer\OfferSearchServiceInterface;
use CultuurNet\UDB3\Search\QueryStringFactoryInterface;
use CultuurNet\UDB3\Search\Region\RegionId;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -37,12 +38,14 @@ class OfferSearchController
* @param OfferSearchServiceInterface $searchService
* @param StringLiteral $regionIndexName
* @param StringLiteral $regionDocumentType
* @param QueryStringFactoryInterface $queryStringFactory
* @param PagedCollectionFactoryInterface|null $pagedCollectionFactory
*/
public function __construct(
OfferSearchServiceInterface $searchService,
StringLiteral $regionIndexName,
StringLiteral $regionDocumentType,
QueryStringFactoryInterface $queryStringFactory,
PagedCollectionFactoryInterface $pagedCollectionFactory = null
) {
if (is_null($pagedCollectionFactory)) {
Expand All @@ -52,6 +55,7 @@ public function __construct(
$this->searchService = $searchService;
$this->regionIndexName = $regionIndexName;
$this->regionDocumentType = $regionDocumentType;
$this->queryStringFactory = $queryStringFactory;
$this->pagedCollectionFactory = $pagedCollectionFactory;
}

Expand All @@ -73,6 +77,14 @@ public function search(Request $request)
->withStart(new Natural($start))
->withLimit(new Natural($limit));

if (!empty($request->query->get('q'))) {
$parameters = $parameters->withQueryString(
$this->queryStringFactory->fromString(
$request->query->get('q')
)
);
}

if (!empty($request->query->get('regionId'))) {
$parameters = $parameters->withRegion(
new RegionId($request->query->get('regionId')),
Expand Down
9 changes: 9 additions & 0 deletions tests/MockQueryString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace CultuurNet\UDB3\Search\Http;

use CultuurNet\UDB3\Search\AbstractQueryString;

class MockQueryString extends AbstractQueryString
{
}
17 changes: 17 additions & 0 deletions tests/MockQueryStringFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace CultuurNet\UDB3\Search\Http;

use CultuurNet\UDB3\Search\QueryStringFactoryInterface;

class MockQueryStringFactory implements QueryStringFactoryInterface
{
/**
* @param string $queryString
* @return MockQueryString
*/
public function fromString($queryString)
{
return new MockQueryString($queryString);
}
}
14 changes: 13 additions & 1 deletion tests/OfferSearchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class OfferSearchControllerTest extends \PHPUnit_Framework_TestCase
*/
private $regionDocumentType;

/**
* @var MockQueryStringFactory
*/
private $queryStringFactory;

/**
* @var OfferSearchController
*/
Expand All @@ -40,10 +45,13 @@ public function setUp()
$this->regionIndexName = new StringLiteral('geoshapes');
$this->regionDocumentType = new StringLiteral('region');

$this->queryStringFactory = new MockQueryStringFactory();

$this->controller = new OfferSearchController(
$this->searchService,
$this->regionIndexName,
$this->regionDocumentType
$this->regionDocumentType,
$this->queryStringFactory
);
}

Expand All @@ -56,11 +64,15 @@ public function it_returns_a_paged_collection_of_search_results_based_on_request
[
'start' => 30,
'limit' => 10,
'q' => 'dag van de fiets',
'regionId' => 'gem-leuven',
]
);

$expectedSearchParameters = (new OfferSearchParameters())
->withQueryString(
new MockQueryString('dag van de fiets')
)
->withRegion(
new RegionId('gem-leuven'),
$this->regionIndexName,
Expand Down

0 comments on commit aa4bad9

Please sign in to comment.