From b2f85ca82236afb829737a0ed9643b3b8a7670ea Mon Sep 17 00:00:00 2001 From: Alex Zamponi <562324+alexz707@users.noreply.github.com> Date: Mon, 4 Mar 2024 12:15:17 +0100 Subject: [PATCH 1/2] Add AssetPathFilter, add Search object --- config/api_platform/resources/asset.yaml | 2 + config/services.yaml | 11 +- ...ilter.php => AssetExcludeFolderFilter.php} | 21 ++-- src/Filter/AssetIdSearchFilter.php | 17 ++- src/Filter/AssetParentIdFilter.php | 17 ++- src/Filter/AssetPathFilter.php | 101 ++++++++++++++++++ src/Service/AssetSearchResult.php | 10 +- src/Service/AssetSearchService.php | 20 ++-- src/Service/AssetSearchServiceInterface.php | 18 ++-- .../AssetSearchAdapterInterface.php | 16 +-- src/Service/GenericData/V1/AssetQuery.php | 64 +++++++++++ .../GenericData/V1/AssetQueryContextTrait.php | 23 ++++ .../GenericData/V1/AssetQueryProvider.php | 18 ++++ .../V1/AssetQueryProviderInterface.php | 9 ++ .../GenericData/V1/AssetSearchAdapter.php | 28 +---- src/State/AssetProvider.php | 20 ++-- 16 files changed, 313 insertions(+), 82 deletions(-) rename src/Filter/{AssetFolderFilter.php => AssetExcludeFolderFilter.php} (61%) create mode 100644 src/Filter/AssetPathFilter.php create mode 100644 src/Service/GenericData/V1/AssetQuery.php create mode 100644 src/Service/GenericData/V1/AssetQueryContextTrait.php create mode 100644 src/Service/GenericData/V1/AssetQueryProvider.php create mode 100644 src/Service/GenericData/V1/AssetQueryProviderInterface.php diff --git a/config/api_platform/resources/asset.yaml b/config/api_platform/resources/asset.yaml index a9c933318..cfb93569e 100644 --- a/config/api_platform/resources/asset.yaml +++ b/config/api_platform/resources/asset.yaml @@ -5,6 +5,8 @@ resources: filters: - Pimcore\Bundle\StudioApiBundle\Filter\AssetParentIdFilter - Pimcore\Bundle\StudioApiBundle\Filter\AssetIdSearchFilter + - Pimcore\Bundle\StudioApiBundle\Filter\AssetExcludeFolderFilter + - Pimcore\Bundle\StudioApiBundle\Filter\AssetPathFilter paginationClientItemsPerPage: true ApiPlatform\Metadata\Get: normalizationContext: diff --git a/config/services.yaml b/config/services.yaml index de85f81de..ce14d9ad5 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -35,6 +35,12 @@ services: Pimcore\Bundle\StudioApiBundle\Filter\AssetIdSearchFilter: tags: [ 'api_platform.filter' ] + Pimcore\Bundle\StudioApiBundle\Filter\AssetExcludeFolderFilter: + tags: [ 'api_platform.filter' ] + + Pimcore\Bundle\StudioApiBundle\Filter\AssetPathFilter: + tags: [ 'api_platform.filter' ] + # Hydrators Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Hydrator\Asset\ArchiveHydratorInterface: class: Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Hydrator\Asset\ArchiveHydrator @@ -72,4 +78,7 @@ services: class: Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetSearchAdapter Pimcore\Bundle\StudioApiBundle\Service\IconServiceInterface: - class: Pimcore\Bundle\StudioApiBundle\Service\IconService \ No newline at end of file + class: Pimcore\Bundle\StudioApiBundle\Service\IconService + + Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryProviderInterface: + class: Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryProvider \ No newline at end of file diff --git a/src/Filter/AssetFolderFilter.php b/src/Filter/AssetExcludeFolderFilter.php similarity index 61% rename from src/Filter/AssetFolderFilter.php rename to src/Filter/AssetExcludeFolderFilter.php index 531c1ecbd..3eb36391a 100644 --- a/src/Filter/AssetFolderFilter.php +++ b/src/Filter/AssetExcludeFolderFilter.php @@ -14,25 +14,32 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; use ApiPlatform\Serializer\Filter\FilterInterface; - use Pimcore\Bundle\StudioApiBundle\Dto\Asset; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryContextTrait; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryProviderInterface; use Symfony\Component\HttpFoundation\Request; -final class AssetFolderFilter implements FilterInterface +final class AssetExcludeFolderFilter implements FilterInterface { - public const ASSET_FOLDER_FILTER_CONTEXT = 'asset_folder_filter'; + use AssetQueryContextTrait; + + private const FOLDER_FILTER_QUERY_PARAM = 'excludeFolders'; - private const FOLDER_FILTER_QUERY_PARAM = 'filterFolders'; + public function __construct(AssetQueryProviderInterface $assetQueryProvider) + { + $this->assetQueryProvider = $assetQueryProvider; + } public function apply(Request $request, bool $normalization, array $attributes, array &$context): void { - $parentId = $request->query->get(self::FOLDER_FILTER_QUERY_PARAM); + $excludeFolders = $request->query->get(self::FOLDER_FILTER_QUERY_PARAM); - if (!$parentId) { + if ($excludeFolders !== 'true') { return; } - $context[self::ASSET_FOLDER_FILTER_CONTEXT] = (bool)$parentId; + $assetQuery = $this->getAssetQuery($context)->excludeFolders(); + $this->setAssetQuery($context, $assetQuery); } public function getDescription(string $resourceClass): array diff --git a/src/Filter/AssetIdSearchFilter.php b/src/Filter/AssetIdSearchFilter.php index e06078cbe..fadb13c5d 100644 --- a/src/Filter/AssetIdSearchFilter.php +++ b/src/Filter/AssetIdSearchFilter.php @@ -14,16 +14,22 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; use ApiPlatform\Serializer\Filter\FilterInterface; - use Pimcore\Bundle\StudioApiBundle\Dto\Asset; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryContextTrait; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryProviderInterface; use Symfony\Component\HttpFoundation\Request; final class AssetIdSearchFilter implements FilterInterface { - public const ASSET_ID_SEARCH_FILTER = 'asset_id_search_filter'; + use AssetQueryContextTrait; private const ID_SEARCH_FILTER_QUERY_PARAM = 'idSearchTerm'; + public function __construct(AssetQueryProviderInterface $assetQueryProvider) + { + $this->assetQueryProvider = $assetQueryProvider; + } + public function apply(Request $request, bool $normalization, array $attributes, array &$context): void { $searchIdTerm = $request->query->get(self::ID_SEARCH_FILTER_QUERY_PARAM); @@ -32,7 +38,8 @@ public function apply(Request $request, bool $normalization, array $attributes, return; } - $context[self::ASSET_ID_SEARCH_FILTER] = $searchIdTerm; + $assetQuery = $this->getAssetQuery($context)->setSearchTerm($searchIdTerm); + $this->setAssetQuery($context, $assetQuery); } public function getDescription(string $resourceClass): array @@ -43,9 +50,9 @@ public function getDescription(string $resourceClass): array 'type' => 'string', 'required' => false, 'is_collection' => false, - 'description' => 'Filters assets by matching ids. As a wildcard, you can use *.', + 'description' => 'Filter assets by matching ids. As a wildcard * can be used', 'openapi' => [ - 'description' => 'Filters assets by matching ids. As a wildcard, you can use *.', + 'description' => 'Filter assets by matching ids. As a wildcard * can be used', ], ], ]; diff --git a/src/Filter/AssetParentIdFilter.php b/src/Filter/AssetParentIdFilter.php index 64323c2b8..924caf091 100644 --- a/src/Filter/AssetParentIdFilter.php +++ b/src/Filter/AssetParentIdFilter.php @@ -14,16 +14,22 @@ namespace Pimcore\Bundle\StudioApiBundle\Filter; use ApiPlatform\Serializer\Filter\FilterInterface; - use Pimcore\Bundle\StudioApiBundle\Dto\Asset; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryContextTrait; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryProviderInterface; use Symfony\Component\HttpFoundation\Request; final class AssetParentIdFilter implements FilterInterface { - public const ASSET_PARENT_ID_FILTER_CONTEXT = 'asset_parent_id_filter'; + use AssetQueryContextTrait; private const PARENT_ID_QUERY_PARAM = 'parentId'; + public function __construct(AssetQueryProviderInterface $assetQueryProvider) + { + $this->assetQueryProvider = $assetQueryProvider; + } + public function apply(Request $request, bool $normalization, array $attributes, array &$context): void { $parentId = $request->query->get(self::PARENT_ID_QUERY_PARAM); @@ -32,7 +38,8 @@ public function apply(Request $request, bool $normalization, array $attributes, return; } - $context[self::ASSET_PARENT_ID_FILTER_CONTEXT] = (int)$parentId; + $assetQuery = $this->getAssetQuery($context)->filterParentId((int)$parentId); + $this->setAssetQuery($context, $assetQuery); } public function getDescription(string $resourceClass): array @@ -43,9 +50,9 @@ public function getDescription(string $resourceClass): array 'type' => 'int', 'required' => false, 'is_collection' => false, - 'description' => 'Filters assets by parent id.', + 'description' => 'Filter assets by parent id.', 'openapi' => [ - 'description' => 'Filters assets by parent id.', + 'description' => 'Filter assets by parent id.', ], ], ]; diff --git a/src/Filter/AssetPathFilter.php b/src/Filter/AssetPathFilter.php new file mode 100644 index 000000000..aa17f9877 --- /dev/null +++ b/src/Filter/AssetPathFilter.php @@ -0,0 +1,101 @@ +assetQueryProvider = $assetQueryProvider; + } + + public function apply(Request $request, bool $normalization, array $attributes, array &$context): void + { + $path = $request->query->get(self::ASSET_PATH_QUERY_PARAM); + + if (!$path) { + return; + } + + $includeDescendants = $this->getBooleanValueFromQuery( + $request, + self::ASSET_PATH_INCLUDE_DESCENDANTS_PARAM, + false + ); + + $includeParent = $this->getBooleanValueFromQuery( + $request, + self::ASSET_PATH_INCLUDE_PARENT_PARAM, + false + ); + + $assetQuery = $this->getAssetQuery($context)->filterPath($path, $includeDescendants, $includeParent); + $this->setAssetQuery($context, $assetQuery); + } + + public function getDescription(string $resourceClass): array + { + return [ + self::ASSET_PATH_QUERY_PARAM => [ + 'property' => Asset::class, + 'type' => 'string', + 'required' => false, + 'is_collection' => false, + 'description' => 'Filter assets by path.', + 'openapi' => [ + 'description' => 'Filter assets by path.', + ], + ], + self::ASSET_PATH_INCLUDE_PARENT_PARAM => [ + 'property' => Asset::class, + 'type' => 'bool', + 'required' => false, + 'is_collection' => false, + 'description' => 'Include the parent item in the result.', + 'openapi' => [ + 'description' => 'Include the parent item in the result.', + ], + ], + self::ASSET_PATH_INCLUDE_DESCENDANTS_PARAM => [ + 'property' => Asset::class, + 'type' => 'bool', + 'required' => false, + 'is_collection' => false, + 'description' => 'Include all descendants in the result.', + 'openapi' => [ + 'description' => 'Include all descendants in the result.', + ], + ], + ]; + } + + private function getBooleanValueFromQuery(Request $request, string $queryName, bool $defaultValue): bool + { + return filter_var( + $request->query->get($queryName, $defaultValue), + FILTER_VALIDATE_BOOLEAN + ); + } +} diff --git a/src/Service/AssetSearchResult.php b/src/Service/AssetSearchResult.php index 64f040a76..7d171e172 100644 --- a/src/Service/AssetSearchResult.php +++ b/src/Service/AssetSearchResult.php @@ -14,6 +14,14 @@ namespace Pimcore\Bundle\StudioApiBundle\Service; use Pimcore\Bundle\StudioApiBundle\Dto\Asset; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Archive; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Audio; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Document; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Folder; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Text; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Unknown; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Video; final readonly class AssetSearchResult { @@ -37,7 +45,7 @@ public function getTotalItems(): int } /** - * @return array + * @return array */ public function getItems(): array { diff --git a/src/Service/AssetSearchService.php b/src/Service/AssetSearchService.php index 2990808af..71c162849 100644 --- a/src/Service/AssetSearchService.php +++ b/src/Service/AssetSearchService.php @@ -14,7 +14,16 @@ namespace Pimcore\Bundle\StudioApiBundle\Service; use Pimcore\Bundle\StudioApiBundle\Dto\Asset; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Archive; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Audio; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Document; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Folder; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Text; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Unknown; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Video; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\AssetSearchAdapterInterface; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery; final readonly class AssetSearchService implements AssetSearchServiceInterface { @@ -22,16 +31,11 @@ public function __construct(private AssetSearchAdapterInterface $assetSearchAdap { } - public function searchAssets( - int $page = 1, - int $pageSize = 50, - ?string $query = null, - ?int $parentId = null - ): AssetSearchResult { - return $this->assetSearchAdapter->searchAsset($page, $pageSize, $query, $parentId); + public function searchAssets(AssetQuery $assetQuery): AssetSearchResult { + return $this->assetSearchAdapter->searchAssets($assetQuery); } - public function getAssetById(int $id): ?Asset + public function getAssetById(int $id): Asset|Archive|Audio|Document|Folder|Image|Text|Unknown|Video|null { return $this->assetSearchAdapter->getAssetById($id); } diff --git a/src/Service/AssetSearchServiceInterface.php b/src/Service/AssetSearchServiceInterface.php index 1fd4cc1a2..b8d6f35c2 100644 --- a/src/Service/AssetSearchServiceInterface.php +++ b/src/Service/AssetSearchServiceInterface.php @@ -14,15 +14,19 @@ namespace Pimcore\Bundle\StudioApiBundle\Service; use Pimcore\Bundle\StudioApiBundle\Dto\Asset; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Archive; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Audio; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Document; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Folder; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Text; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Unknown; +use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Video; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery; interface AssetSearchServiceInterface { - public function searchAssets( - int $page = 1, - int $pageSize = 50, - ?string $query = null, - ?int $parentId = null - ): AssetSearchResult; + public function searchAssets(AssetQuery $assetQuery): AssetSearchResult; - public function getAssetById(int $id): ?Asset; + public function getAssetById(int $id): Asset|Archive|Audio|Document|Folder|Image|Text|Unknown|Video|null; } diff --git a/src/Service/GenericData/AssetSearchAdapterInterface.php b/src/Service/GenericData/AssetSearchAdapterInterface.php index 5a96f3066..56b4e3068 100644 --- a/src/Service/GenericData/AssetSearchAdapterInterface.php +++ b/src/Service/GenericData/AssetSearchAdapterInterface.php @@ -15,23 +15,11 @@ use Pimcore\Bundle\StudioApiBundle\Dto\Asset; use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchResult; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery; interface AssetSearchAdapterInterface { - /** - * @param int $page - * @param int $pageSize - * @param string|null $searchTerm - * @param int|null $parentId - * - * @return AssetSearchResult - */ - public function searchAsset( - int $page, - int $pageSize, - ?string $searchTerm, - ?int $parentId = null - ): AssetSearchResult; + public function searchAssets(AssetQuery $assetQuery): AssetSearchResult; public function getAssetById(int $id): ?Asset; } diff --git a/src/Service/GenericData/V1/AssetQuery.php b/src/Service/GenericData/V1/AssetQuery.php new file mode 100644 index 000000000..d0f1590d9 --- /dev/null +++ b/src/Service/GenericData/V1/AssetQuery.php @@ -0,0 +1,64 @@ +search->setPage($page); + return $this; + } + + public function setPageSize(int $pageSize): self + { + $this->search->setPageSize($pageSize); + return $this; + } + + public function filterParentId(?int $parentId): self + { + if ($parentId !== null) { + $this->search->addModifier(new ParentIdFilter($parentId)); + } + return $this; + } + + public function filterPath(string $path, bool $includeDescendants, bool $includeParent): self + { + $this->search->addModifier(new PathFilter($path, !$includeDescendants, $includeParent)); + return $this; + } + + public function setSearchTerm(?string $term): self + { + if ($term !== null) { + $this->search->addModifier(new ElementKeySearch($term)); + } + return $this; + } + + public function excludeFolders(): self + { + $this->search->addModifier(new ExcludeFoldersFilter()); + return $this; + } + + public function getSearch(): SearchInterface + { + return $this->search; + } +} \ No newline at end of file diff --git a/src/Service/GenericData/V1/AssetQueryContextTrait.php b/src/Service/GenericData/V1/AssetQueryContextTrait.php new file mode 100644 index 000000000..e7c1f2683 --- /dev/null +++ b/src/Service/GenericData/V1/AssetQueryContextTrait.php @@ -0,0 +1,23 @@ +assetQueryProvider->createAssetQuery(); + } + + return $context[AssetQuery::ASSET_QUERY_ID]; + } +} \ No newline at end of file diff --git a/src/Service/GenericData/V1/AssetQueryProvider.php b/src/Service/GenericData/V1/AssetQueryProvider.php new file mode 100644 index 000000000..5a11143b3 --- /dev/null +++ b/src/Service/GenericData/V1/AssetQueryProvider.php @@ -0,0 +1,18 @@ +searchProvider->createAssetSearch()); + } +} \ No newline at end of file diff --git a/src/Service/GenericData/V1/AssetQueryProviderInterface.php b/src/Service/GenericData/V1/AssetQueryProviderInterface.php new file mode 100644 index 000000000..ad1d39340 --- /dev/null +++ b/src/Service/GenericData/V1/AssetQueryProviderInterface.php @@ -0,0 +1,9 @@ +searchProvider->createAssetSearch(); - $search->setPageSize($pageSize); - $search->setPage($page); - - if ($parentId !== null) { - $search->addModifier(new ParentIdFilter($parentId)); - } - - if ($searchTerm !== null) { - $search->addModifier(new ElementKeySearch($searchTerm)); - } - - $searchResult = $this->searchService->search($search); + $searchResult = $this->searchService->search($assetQuery->getSearch()); $result = []; foreach ($searchResult->getItems() as $item) { $result[] = $this->assetHydratorService->hydrate($item); diff --git a/src/State/AssetProvider.php b/src/State/AssetProvider.php index 1d2dcb375..dbd1189b4 100644 --- a/src/State/AssetProvider.php +++ b/src/State/AssetProvider.php @@ -19,27 +19,31 @@ use ApiPlatform\State\Pagination\TraversablePaginator; use ApiPlatform\State\ProviderInterface; use ArrayIterator; -use Pimcore\Bundle\StudioApiBundle\Filter\AssetIdSearchFilter; -use Pimcore\Bundle\StudioApiBundle\Filter\AssetParentIdFilter; use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryContextTrait; +use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQueryProviderInterface; final readonly class AssetProvider implements ProviderInterface { + use AssetQueryContextTrait; + public function __construct( + AssetQueryProviderInterface $assetQueryProvider, private AssetSearchServiceInterface $assetSearchService, private Pagination $pagination ) { + $this->assetQueryProvider = $assetQueryProvider; } public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null { if ($operation instanceof CollectionOperationInterface) { - $searchResult = $this->assetSearchService->searchAssets( - $this->pagination->getPage($context), - $this->pagination->getLimit($operation, $context), - $context[AssetIdSearchFilter::ASSET_ID_SEARCH_FILTER] ?? null, - $context[AssetParentIdFilter::ASSET_PARENT_ID_FILTER_CONTEXT] ?? null, - ); + + $assetQuery = $this->getAssetQuery($context) + ->setPage($this->pagination->getPage($context)) + ->setPageSize($this->pagination->getLimit($operation, $context)); + + $searchResult = $this->assetSearchService->searchAssets($assetQuery); return new TraversablePaginator( new ArrayIterator($searchResult->getItems()), From 78c47adb6a80567102827a5abfa96593af607a9a Mon Sep 17 00:00:00 2001 From: alexz707 Date: Mon, 4 Mar 2024 11:15:43 +0000 Subject: [PATCH 2/2] Apply php-cs-fixer changes --- src/Filter/AssetPathFilter.php | 3 +++ src/Service/AssetSearchService.php | 3 ++- src/Service/GenericData/V1/AssetQuery.php | 18 +++++++++++++++++- .../GenericData/V1/AssetQueryContextTrait.php | 12 +++++++++++- .../GenericData/V1/AssetQueryProvider.php | 12 +++++++++++- .../V1/AssetQueryProviderInterface.php | 12 +++++++++++- 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/Filter/AssetPathFilter.php b/src/Filter/AssetPathFilter.php index aa17f9877..c551725d1 100644 --- a/src/Filter/AssetPathFilter.php +++ b/src/Filter/AssetPathFilter.php @@ -22,8 +22,11 @@ final class AssetPathFilter implements FilterInterface { use AssetQueryContextTrait; + private const ASSET_PATH_QUERY_PARAM = 'assetPath'; + private const ASSET_PATH_INCLUDE_PARENT_PARAM = 'assetPathIncludeParent'; + private const ASSET_PATH_INCLUDE_DESCENDANTS_PARAM = 'assetPathIncludeDescendants'; public function __construct(AssetQueryProviderInterface $assetQueryProvider) diff --git a/src/Service/AssetSearchService.php b/src/Service/AssetSearchService.php index 71c162849..e57c9afeb 100644 --- a/src/Service/AssetSearchService.php +++ b/src/Service/AssetSearchService.php @@ -31,7 +31,8 @@ public function __construct(private AssetSearchAdapterInterface $assetSearchAdap { } - public function searchAssets(AssetQuery $assetQuery): AssetSearchResult { + public function searchAssets(AssetQuery $assetQuery): AssetSearchResult + { return $this->assetSearchAdapter->searchAssets($assetQuery); } diff --git a/src/Service/GenericData/V1/AssetQuery.php b/src/Service/GenericData/V1/AssetQuery.php index d0f1590d9..f712cbf7a 100644 --- a/src/Service/GenericData/V1/AssetQuery.php +++ b/src/Service/GenericData/V1/AssetQuery.php @@ -1,6 +1,16 @@ search->setPage($page); + return $this; } public function setPageSize(int $pageSize): self { $this->search->setPageSize($pageSize); + return $this; } @@ -34,12 +46,14 @@ public function filterParentId(?int $parentId): self if ($parentId !== null) { $this->search->addModifier(new ParentIdFilter($parentId)); } + return $this; } public function filterPath(string $path, bool $includeDescendants, bool $includeParent): self { $this->search->addModifier(new PathFilter($path, !$includeDescendants, $includeParent)); + return $this; } @@ -48,12 +62,14 @@ public function setSearchTerm(?string $term): self if ($term !== null) { $this->search->addModifier(new ElementKeySearch($term)); } + return $this; } public function excludeFolders(): self { $this->search->addModifier(new ExcludeFoldersFilter()); + return $this; } @@ -61,4 +77,4 @@ public function getSearch(): SearchInterface { return $this->search; } -} \ No newline at end of file +} diff --git a/src/Service/GenericData/V1/AssetQueryContextTrait.php b/src/Service/GenericData/V1/AssetQueryContextTrait.php index e7c1f2683..f58d1dc46 100644 --- a/src/Service/GenericData/V1/AssetQueryContextTrait.php +++ b/src/Service/GenericData/V1/AssetQueryContextTrait.php @@ -1,6 +1,16 @@ searchProvider->createAssetSearch()); } -} \ No newline at end of file +} diff --git a/src/Service/GenericData/V1/AssetQueryProviderInterface.php b/src/Service/GenericData/V1/AssetQueryProviderInterface.php index ad1d39340..69ca303ca 100644 --- a/src/Service/GenericData/V1/AssetQueryProviderInterface.php +++ b/src/Service/GenericData/V1/AssetQueryProviderInterface.php @@ -1,9 +1,19 @@