diff --git a/config/filters.yaml b/config/filters.yaml index c96ee6ab3..3b688891c 100644 --- a/config/filters.yaml +++ b/config/filters.yaml @@ -5,6 +5,8 @@ services: public: false #Filter + + #Common Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterLoaderInterface: class: Pimcore\Bundle\StudioApiBundle\Service\Filter\Loader\TaggedIteratorAdapter @@ -27,4 +29,8 @@ services: tags: [ 'pimcore.studio_api.collection.filter' ] Pimcore\Bundle\StudioApiBundle\Filter\PathFilter: - tags: [ 'pimcore.studio_api.collection.filter' ] \ No newline at end of file + tags: [ 'pimcore.studio_api.collection.filter' ] + + # DataObject + Pimcore\Bundle\StudioApiBundle\Filter\DataObject\ClassIdFilter: + tags: [ 'pimcore.studio_api.collection.filter' ] \ No newline at end of file diff --git a/src/Attributes/Parameters/Query/ClassIdParameter.php b/src/Attributes/Parameters/Query/ClassIdParameter.php new file mode 100644 index 000000000..c71816cc4 --- /dev/null +++ b/src/Attributes/Parameters/Query/ClassIdParameter.php @@ -0,0 +1,47 @@ +load() as $classDefinition) { + $classNames[] = $classDefinition->getId(); + $description .= '
' . $classDefinition->getId() . ' => ' . $classDefinition->getName(); + } + $description .= '

'; + + parent::__construct( + name: 'classId', + description: $description, + in: 'query', + required: false, + schema: new Schema(type: 'string', enum: $classNames, example: null), + ); + } +} diff --git a/src/Controller/Api/Assets/CollectionController.php b/src/Controller/Api/Assets/CollectionController.php index 9bdd6a7e2..def4ae18a 100644 --- a/src/Controller/Api/Assets/CollectionController.php +++ b/src/Controller/Api/Assets/CollectionController.php @@ -32,7 +32,7 @@ use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController; use Pimcore\Bundle\StudioApiBundle\Controller\Trait\PaginatedResponseTrait; use Pimcore\Bundle\StudioApiBundle\Dto\Asset; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException; use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface; use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface; @@ -83,10 +83,10 @@ public function __construct( /** * @throws InvalidQueryTypeException */ - public function getAssets(#[MapQueryString] Collection $collection): JsonResponse + public function getAssets(#[MapQueryString] Parameters $parameters): JsonResponse { /** @var AssetQuery $assetQuery */ - $assetQuery = $this->filterService->applyCollectionFilter($collection, 'asset'); + $assetQuery = $this->filterService->applyCollectionFilter($parameters, 'asset'); $result = $this->assetSearchService->searchAssets($assetQuery); diff --git a/src/Controller/Api/DataObjects/CollectionController.php b/src/Controller/Api/DataObjects/CollectionController.php index 1b321ba39..bed874e6f 100644 --- a/src/Controller/Api/DataObjects/CollectionController.php +++ b/src/Controller/Api/DataObjects/CollectionController.php @@ -18,6 +18,7 @@ use OpenApi\Attributes\Get; use OpenApi\Attributes\JsonContent; +use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Query\ClassIdParameter; use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Query\ExcludeFoldersParameter; use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Query\IdSearchTermParameter; use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Query\PageParameter; @@ -31,8 +32,8 @@ use Pimcore\Bundle\StudioApiBundle\Config\Tags; use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController; use Pimcore\Bundle\StudioApiBundle\Controller\Trait\PaginatedResponseTrait; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; use Pimcore\Bundle\StudioApiBundle\Dto\DataObject; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\DataObjectParameters; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException; use Pimcore\Bundle\StudioApiBundle\Service\DataObjectSearchServiceInterface; use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface; @@ -74,6 +75,7 @@ public function __construct( #[PathParameter] #[PathIncludeParentParameter] #[PathIncludeDescendantsParameter] + #[ClassIdParameter] #[SuccessResponse( description: 'Paginated data objects with total count as header param', content: new JsonContent(ref: DataObject::class) @@ -83,11 +85,11 @@ public function __construct( /** * @throws InvalidQueryTypeException */ - public function getDataObjects(#[MapQueryString] Collection $collection): JsonResponse + public function getDataObjects(#[MapQueryString] DataObjectParameters $parameters): JsonResponse { /** @var DataObjectQuery $dataObjectQuery */ - $dataObjectQuery = $this->filterService->applyCollectionFilter($collection, 'dataObject'); + $dataObjectQuery = $this->filterService->applyCollectionFilter($parameters, 'dataObject'); $result = $this->dataObjectSearchService->searchDataObjects($dataObjectQuery); diff --git a/src/Dto/DataObject.php b/src/Dto/DataObject.php index 2d1565ebc..36e71dc20 100644 --- a/src/Dto/DataObject.php +++ b/src/Dto/DataObject.php @@ -27,7 +27,9 @@ { public function __construct( #[Property(description: 'ID', type: 'integer', example: 83)] - private int $id + private int $id, + #[Property(description: 'className', type: 'string', example: 'car')] + private string $className ) { } @@ -36,4 +38,11 @@ public function getId(): int { return $this->id; } + + public function getClassName(): string + { + return $this->className; + } + + } diff --git a/src/Dto/Filter/DataObjectParameters.php b/src/Dto/Filter/DataObjectParameters.php new file mode 100644 index 000000000..6b3b2453f --- /dev/null +++ b/src/Dto/Filter/DataObjectParameters.php @@ -0,0 +1,48 @@ +classId; + } +} \ No newline at end of file diff --git a/src/Dto/Filter/DataObjectParametersInterface.php b/src/Dto/Filter/DataObjectParametersInterface.php new file mode 100644 index 000000000..b2dd3f06f --- /dev/null +++ b/src/Dto/Filter/DataObjectParametersInterface.php @@ -0,0 +1,22 @@ +getClassId() + ) { + return $query; + } + + return $query->setClassDefinitionId($parameters->getClassId()); + } +} diff --git a/src/Filter/ExcludeFolderFilter.php b/src/Filter/ExcludeFolderFilter.php index d6b3421ad..7b18323e5 100644 --- a/src/Filter/ExcludeFolderFilter.php +++ b/src/Filter/ExcludeFolderFilter.php @@ -16,14 +16,15 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\ParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; final class ExcludeFolderFilter implements FilterInterface { - public function apply(Collection $collection, QueryInterface $query): QueryInterface + public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface { - $excludeFolders = $collection->getExcludeFolders(); + $excludeFolders = $parameters->getExcludeFolders(); if(!$excludeFolders) { return $query; } diff --git a/src/Filter/FilterInterface.php b/src/Filter/FilterInterface.php index 03d4888eb..5fb720b96 100644 --- a/src/Filter/FilterInterface.php +++ b/src/Filter/FilterInterface.php @@ -16,10 +16,11 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\ParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; interface FilterInterface { - public function apply(Collection $collection, QueryInterface $query): QueryInterface; + public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface; } diff --git a/src/Filter/IdSearchFilter.php b/src/Filter/IdSearchFilter.php index 0fa475f06..90760fe9e 100644 --- a/src/Filter/IdSearchFilter.php +++ b/src/Filter/IdSearchFilter.php @@ -16,14 +16,15 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\ParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; final class IdSearchFilter implements FilterInterface { - public function apply(Collection $collection, QueryInterface $query): QueryInterface + public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface { - $idSearchTerm = $collection->getIdSearchTerm(); + $idSearchTerm = $parameters->getIdSearchTerm(); if(!$idSearchTerm) { return $query; diff --git a/src/Filter/PageFilter.php b/src/Filter/PageFilter.php index ef1afaa35..79c5e3c9f 100644 --- a/src/Filter/PageFilter.php +++ b/src/Filter/PageFilter.php @@ -16,13 +16,14 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\ParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; final class PageFilter implements FilterInterface { - public function apply(Collection $collection, QueryInterface $query): QueryInterface + public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface { - return $query->setPage($collection->getPage()); + return $query->setPage($parameters->getPage()); } } diff --git a/src/Filter/PageSizeFilter.php b/src/Filter/PageSizeFilter.php index 9b9753515..71acf271b 100644 --- a/src/Filter/PageSizeFilter.php +++ b/src/Filter/PageSizeFilter.php @@ -16,13 +16,14 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\ParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; final class PageSizeFilter implements FilterInterface { - public function apply(Collection $collection, QueryInterface $query): QueryInterface + public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface { - return $query->setPageSize($collection->getPageSize()); + return $query->setPageSize($parameters->getPageSize()); } } diff --git a/src/Filter/ParentIdFilter.php b/src/Filter/ParentIdFilter.php index fe4c40c69..8a0016e61 100644 --- a/src/Filter/ParentIdFilter.php +++ b/src/Filter/ParentIdFilter.php @@ -16,14 +16,15 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\ParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; final class ParentIdFilter implements FilterInterface { - public function apply(Collection $collection, QueryInterface $query): QueryInterface + public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface { - $parentId = $collection->getParentId(); + $parentId = $parameters->getParentId(); if(!$parentId) { return $query; diff --git a/src/Filter/PathFilter.php b/src/Filter/PathFilter.php index c8c2138dd..eeefe8551 100644 --- a/src/Filter/PathFilter.php +++ b/src/Filter/PathFilter.php @@ -16,16 +16,17 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\ParametersInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; final class PathFilter implements FilterInterface { - public function apply(Collection $collection, QueryInterface $query): QueryInterface + public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface { - $path = $collection->getPath(); - $includeParent = $collection->getPathIncludeParent(); - $includeDescendants = $collection->getPathIncludeDescendants(); + $path = $parameters->getPath(); + $includeParent = $parameters->getPathIncludeParent(); + $includeDescendants = $parameters->getPathIncludeDescendants(); if (!$path) { return $query; diff --git a/src/Service/Filter/FilterService.php b/src/Service/Filter/FilterService.php index 33d32c3ee..ec6c176b6 100644 --- a/src/Service/Filter/FilterService.php +++ b/src/Service/Filter/FilterService.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioApiBundle\Service\Filter; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException; use Pimcore\Bundle\StudioApiBundle\Factory\QueryFactoryInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; @@ -32,7 +32,7 @@ public function __construct( /** * @throws InvalidQueryTypeException */ - public function applyCollectionFilter(Collection $collection, string $type): QueryInterface + public function applyCollectionFilter(Parameters $collection, string $type): QueryInterface { $query = $this->queryFactory->create($type); foreach ($this->filterLoader->loadFilters() as $filter) { diff --git a/src/Service/Filter/FilterServiceInterface.php b/src/Service/Filter/FilterServiceInterface.php index cb0339592..b42b32a5c 100644 --- a/src/Service/Filter/FilterServiceInterface.php +++ b/src/Service/Filter/FilterServiceInterface.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioApiBundle\Service\Filter; -use Pimcore\Bundle\StudioApiBundle\Dto\Collection; +use Pimcore\Bundle\StudioApiBundle\Dto\Filter\Parameters; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; @@ -25,5 +25,5 @@ interface FilterServiceInterface /** * @throws InvalidQueryTypeException */ - public function applyCollectionFilter(Collection $collection, string $type): QueryInterface; + public function applyCollectionFilter(Parameters $collection, string $type): QueryInterface; } diff --git a/src/Service/GenericData/V1/DataObjectSearchAdapter.php b/src/Service/GenericData/V1/DataObjectSearchAdapter.php index d86034280..7b5042f32 100644 --- a/src/Service/GenericData/V1/DataObjectSearchAdapter.php +++ b/src/Service/GenericData/V1/DataObjectSearchAdapter.php @@ -34,10 +34,14 @@ public function __construct( public function searchDataObjects(DataObjectQuery $dataObjectQuery): DataObjectSearchResult { $searchResult = $this->searchService->search($dataObjectQuery->getSearch()); - $result = array_map( - static fn (int $id) => new DataObject($id), - $searchResult->getIds() - ); + + foreach($searchResult->getIds() as $id) { + $dataObject = $this->getDataObjectById($id); + if (!$dataObject) { + continue; + } + $result[] = new DataObject($dataObject->getId(), $dataObject->getClassName()); + } return new DataObjectSearchResult( $result,