diff --git a/src/Controller/Api/Assets/CollectionController.php b/src/Controller/Api/Assets/CollectionController.php index ce209aa63..da54befb1 100644 --- a/src/Controller/Api/Assets/CollectionController.php +++ b/src/Controller/Api/Assets/CollectionController.php @@ -37,7 +37,7 @@ use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController; use Pimcore\Bundle\StudioApiBundle\Controller\Trait\PaginatedResponseTrait; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParameters; use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface; use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface; use Symfony\Component\HttpFoundation\JsonResponse; @@ -90,7 +90,7 @@ public function __construct( #[MethodNotAllowedResponse] #[UnsupportedMediaTypeResponse] #[UnprocessableContentResponse] - public function getAssets(#[MapQueryString] Parameters $parameters): JsonResponse + public function getAssets(#[MapQueryString] ElementParameters $parameters): JsonResponse { $assetQuery = $this->filterService->applyFilters( $parameters, diff --git a/src/Filter/DataObject/ClassNameFilter.php b/src/Filter/DataObject/ClassNameFilter.php index 0b53a279a..578f390ba 100644 --- a/src/Filter/DataObject/ClassNameFilter.php +++ b/src/Filter/DataObject/ClassNameFilter.php @@ -18,8 +18,8 @@ use Exception; use Pimcore\Bundle\StudioApiBundle\Filter\FilterInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\DataObjectParametersInterface; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; @@ -31,7 +31,7 @@ final class ClassNameFilter implements FilterInterface /** * @throws Exception */ - public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface + public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface { if( !$parameters instanceof DataObjectParametersInterface || diff --git a/src/Filter/ExcludeFolderFilter.php b/src/Filter/ExcludeFolderFilter.php index f8e3b1c05..957d702ea 100644 --- a/src/Filter/ExcludeFolderFilter.php +++ b/src/Filter/ExcludeFolderFilter.php @@ -16,7 +16,8 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; /** @@ -24,8 +25,12 @@ */ final class ExcludeFolderFilter implements FilterInterface { - public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface + public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface { + if (!$parameters instanceof ElementParametersInterface) { + return $query; + } + $excludeFolders = $parameters->getExcludeFolders(); if(!$excludeFolders) { return $query; diff --git a/src/Filter/FilterInterface.php b/src/Filter/FilterInterface.php index b37ba0886..04bbc1066 100644 --- a/src/Filter/FilterInterface.php +++ b/src/Filter/FilterInterface.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; /** @@ -24,5 +24,5 @@ */ interface FilterInterface { - public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface; + public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface; } diff --git a/src/Filter/IdSearchFilter.php b/src/Filter/IdSearchFilter.php index 685d152d2..4c32e508f 100644 --- a/src/Filter/IdSearchFilter.php +++ b/src/Filter/IdSearchFilter.php @@ -16,7 +16,8 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; /** @@ -24,8 +25,12 @@ */ final class IdSearchFilter implements FilterInterface { - public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface + public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface { + if (!$parameters instanceof ElementParametersInterface) { + return $query; + } + $idSearchTerm = $parameters->getIdSearchTerm(); if(!$idSearchTerm) { diff --git a/src/Filter/PageFilter.php b/src/Filter/PageFilter.php index 6397e22e7..6ff42bdbc 100644 --- a/src/Filter/PageFilter.php +++ b/src/Filter/PageFilter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; /** @@ -24,7 +24,7 @@ */ final class PageFilter implements FilterInterface { - public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface + public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface { return $query->setPage($parameters->getPage()); } diff --git a/src/Filter/PageSizeFilter.php b/src/Filter/PageSizeFilter.php index e47d88dbb..c7de050fa 100644 --- a/src/Filter/PageSizeFilter.php +++ b/src/Filter/PageSizeFilter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; /** @@ -24,7 +24,7 @@ */ final class PageSizeFilter implements FilterInterface { - public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface + public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface { return $query->setPageSize($parameters->getPageSize()); } diff --git a/src/Filter/ParentIdFilter.php b/src/Filter/ParentIdFilter.php index 1da20e45c..ba49a4109 100644 --- a/src/Filter/ParentIdFilter.php +++ b/src/Filter/ParentIdFilter.php @@ -16,7 +16,8 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; /** @@ -24,8 +25,12 @@ */ final class ParentIdFilter implements FilterInterface { - public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface + public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface { + if (!$parameters instanceof ElementParametersInterface) { + return $query; + } + $parentId = $parameters->getParentId(); if(!$parentId) { diff --git a/src/Filter/PathFilter.php b/src/Filter/PathFilter.php index edd9e5175..5bfc5a4c9 100644 --- a/src/Filter/PathFilter.php +++ b/src/Filter/PathFilter.php @@ -16,7 +16,8 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; /** @@ -24,8 +25,12 @@ */ final class PathFilter implements FilterInterface { - public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface + public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface { + if (!$parameters instanceof ElementParametersInterface) { + return $query; + } + $path = $parameters->getPath(); $includeParent = $parameters->getPathIncludeParent(); $includeDescendants = $parameters->getPathIncludeDescendants(); diff --git a/src/Request/Query/Filter/CollectionParameters.php b/src/Request/Query/Filter/CollectionParameters.php new file mode 100644 index 000000000..5e2f05dd7 --- /dev/null +++ b/src/Request/Query/Filter/CollectionParameters.php @@ -0,0 +1,54 @@ +validate(); + } + + public function getPage(): int + { + return $this->page; + } + + public function getPageSize(): int + { + return $this->pageSize; + } + + private function validate(): void + { + new PositiveInteger($this->page); + new PositiveInteger($this->pageSize); + } +} diff --git a/src/Request/Query/Filter/CollectionParametersInterface.php b/src/Request/Query/Filter/CollectionParametersInterface.php new file mode 100644 index 000000000..12e7a5362 --- /dev/null +++ b/src/Request/Query/Filter/CollectionParametersInterface.php @@ -0,0 +1,27 @@ +validate(); - } - - public function getPage(): int - { - return $this->page; - } - - public function getPageSize(): int - { - return $this->pageSize; + parent::__construct($page, $pageSize); } public function getParentId(): ?int @@ -81,10 +64,4 @@ public function getPathIncludeDescendants(): ?bool { return $this->pathIncludeDescendants === 'true'; // TODO: symfony 7.1 will support bool type } - - private function validate(): void - { - new PositiveInteger($this->page); - new PositiveInteger($this->pageSize); - } } diff --git a/src/Request/Query/Filter/ParametersInterface.php b/src/Request/Query/Filter/ElementParametersInterface.php similarity index 96% rename from src/Request/Query/Filter/ParametersInterface.php rename to src/Request/Query/Filter/ElementParametersInterface.php index 0dbc044b9..85b342863 100644 --- a/src/Request/Query/Filter/ParametersInterface.php +++ b/src/Request/Query/Filter/ElementParametersInterface.php @@ -19,7 +19,7 @@ /** * @internal */ -interface ParametersInterface +interface ElementParametersInterface { public function getPage(): int; diff --git a/src/Service/Filter/FilterService.php b/src/Service/Filter/FilterService.php index 9044d96e4..dbc5af2fa 100644 --- a/src/Service/Filter/FilterService.php +++ b/src/Service/Filter/FilterService.php @@ -19,7 +19,8 @@ use Pimcore\Bundle\StudioApiBundle\Exception\InvalidFilterTypeException; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException; use Pimcore\Bundle\StudioApiBundle\Factory\QueryFactoryInterface; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParameters; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; /** @@ -37,7 +38,7 @@ public function __construct( * @throws InvalidQueryTypeException * @throws InvalidFilterTypeException */ - public function applyFilters(Parameters $parameters, string $type): QueryInterface + public function applyFilters(CollectionParametersInterface $parameters, string $type): QueryInterface { $query = $this->queryFactory->create($type); // apply default filters diff --git a/src/Service/Filter/FilterServiceInterface.php b/src/Service/Filter/FilterServiceInterface.php index 2bc6597de..2c0654c80 100644 --- a/src/Service/Filter/FilterServiceInterface.php +++ b/src/Service/Filter/FilterServiceInterface.php @@ -17,7 +17,8 @@ namespace Pimcore\Bundle\StudioApiBundle\Service\Filter; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException; -use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParameters; +use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; /** @@ -34,5 +35,5 @@ interface FilterServiceInterface /** * @throws InvalidQueryTypeException */ - public function applyFilters(Parameters $parameters, string $type): QueryInterface; + public function applyFilters(CollectionParametersInterface $parameters, string $type): QueryInterface; }