Skip to content

Commit

Permalink
IBX-7653: Add FilterParser and IsContainer criterion parser (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
tischsoic authored May 16, 2024
1 parent 7728d69 commit 8df1859
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/bundle/Resources/config/input_parsers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ services:
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.UserMetadata }

Ibexa\Rest\Server\Input\Parser\Criterion\IsContainer:
parent: Ibexa\Rest\Server\Common\Parser
arguments:
$parserTools: '@Ibexa\Rest\Input\ParserTools'
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.IsContainer }

Ibexa\Rest\Server\Input\Parser\Criterion\IsUserBased:
parent: Ibexa\Rest\Server\Common\Parser
arguments:
Expand Down
37 changes: 37 additions & 0 deletions src/lib/Server/Input/Parser/Criterion/IsContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer as IsContainerCriterion;
use Ibexa\Contracts\Rest\Exceptions;
use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
use Ibexa\Rest\Input\BaseParser;
use Ibexa\Rest\Input\ParserTools;

final class IsContainer extends BaseParser
{
private ParserTools $parserTools;

public function __construct(ParserTools $parserTools)
{
$this->parserTools = $parserTools;
}

/**
* @param array<mixed> $data
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher): IsContainerCriterion
{
if (!array_key_exists('IsContainerCriterion', $data)) {
throw new Exceptions\Parser('Invalid <IsContainer> format');
}

return new IsContainerCriterion($this->parserTools->parseBooleanValue($data['IsContainerCriterion']));
}
}
40 changes: 40 additions & 0 deletions tests/bundle/Functional/SearchView/Criterion/IsContainerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\Tests\Bundle\Rest\Functional\SearchView\Criterion;

use Ibexa\Tests\Bundle\Rest\Functional\SearchView\SearchCriterionTestCase;

final class IsContainerTest extends SearchCriterionTestCase
{
/**
* @phpstan-return iterable<
* string,
* array{
* string,
* string,
* int,
* },
* >
*/
public function getCriteriaPayloads(): iterable
{
return [
'is container' => [
'json',
$this->buildJsonCriterionQuery('"IsContainerCriterion": true'),
10,
],
'is not container' => [
'json',
$this->buildJsonCriterionQuery('"IsContainerCriterion": false'),
2,
],
];
}
}

0 comments on commit 8df1859

Please sign in to comment.