Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-5135: Added LocationDepth and IsMainLocation criterion parsers #50

Open
wants to merge 7 commits into
base: 4.5
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
IBX-5135: Added IsMainLocation criterion parser
Steveb-p committed Aug 16, 2023
commit de5c24edae9a502cf833e8e14900fb5b3e70d828
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/input_parsers.yml
Original file line number Diff line number Diff line change
@@ -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
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
@@ -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',
];
}

/**
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>