Skip to content

Commit

Permalink
IBX-5135: Added IsMainLocation criterion parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p committed Feb 21, 2023
1 parent 5703ff5 commit 3388ef2
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/input_parsers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ services:
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.LocationDepth }

Ibexa\Rest\Server\Input\Parser\Criterion\Location\IsMainLocation:
parent: Ibexa\Rest\Server\Common\Parser
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.IsMainLocation }

Ibexa\Rest\Server\Input\Parser\Criterion\Ancestor:
parent: Ibexa\Rest\Server\Common\Parser
class: Ibexa\Rest\Server\Input\Parser\Criterion\Ancestor
Expand Down
26 changes: 26 additions & 0 deletions src/lib/Server/Input/Parser/Criterion/Location/IsMainLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Rest\Server\Input\Parser\Criterion\Location;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Location\IsMainLocation as IsMainLocationCriterion;
use Ibexa\Contracts\Rest\Exceptions;
use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
use Ibexa\Rest\Input\BaseParser;

final class IsMainLocation extends BaseParser
{
public function parse(array $data, ParsingDispatcher $parsingDispatcher): IsMainLocationCriterion
{
if (!array_key_exists('IsMainLocation', $data)) {
throw new Exceptions\Parser('Invalid <IsMainLocation> format');
}

return new IsMainLocationCriterion($data['IsMainLocation']);
}
}
10 changes: 10 additions & 0 deletions tests/bundle/Functional/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public function provideForViewTest(): iterable
file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.json'),
'json',
];

yield $template('IsMainLocation', 'eq', 'xml') => [
file_get_contents(__DIR__ . '/_input/search/IsMainLocation.xml'),
'xml',
];

yield $template('IsMainLocation', 'eq', 'json') => [
file_get_contents(__DIR__ . '/_input/search/IsMainLocation.json'),
'json',
];
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/bundle/Functional/_input/search/IsMainLocation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ViewInput": {
"identifier": "TitleView",
"Query": {
"LocationFilter": {
"IsMainLocation": 1
},
"limit": 10,
"offset": 0
}
}
}
11 changes: 11 additions & 0 deletions tests/bundle/Functional/_input/search/IsMainLocation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<ViewInput>
<identifier>TitleView</identifier>
<Query>
<LocationFilter>
<IsMainLocation>1</IsMainLocation>
</LocationFilter>
<limit>10</limit>
<offset>0</offset>
</Query>
</ViewInput>

0 comments on commit 3388ef2

Please sign in to comment.