|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * This source file is available under the terms of the |
| 6 | + * Pimcore Open Core License (POCL) |
| 7 | + * Full copyright and license information is available in |
| 8 | + * LICENSE.md which is distributed with this source code. |
| 9 | + * |
| 10 | + * @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com) |
| 11 | + * @license Pimcore Open Core License (POCL) |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Pimcore\Bundle\StudioBackendBundle\Search\Controller\SavedSearch; |
| 15 | + |
| 16 | +use OpenApi\Attributes\Get; |
| 17 | +use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; |
| 18 | +use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParameters; |
| 19 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageParameter; |
| 20 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageSizeParameter; |
| 21 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\TextFieldParameter; |
| 22 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection; |
| 23 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson; |
| 24 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; |
| 25 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; |
| 26 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; |
| 27 | +use Pimcore\Bundle\StudioBackendBundle\Search\Schema\ConfigurationListItem; |
| 28 | +use Pimcore\Bundle\StudioBackendBundle\Search\Service\SavedSearchConfigurationServiceInterface; |
| 29 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; |
| 30 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; |
| 31 | +use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait; |
| 32 | +use Symfony\Component\HttpFoundation\JsonResponse; |
| 33 | +use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; |
| 34 | +use Symfony\Component\HttpKernel\Attribute\MapQueryString; |
| 35 | +use Symfony\Component\Routing\Attribute\Route; |
| 36 | +use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 37 | +use Symfony\Component\Serializer\SerializerInterface; |
| 38 | + |
| 39 | +/** |
| 40 | + * @internal |
| 41 | + */ |
| 42 | +final class ListConfigurationsController extends AbstractApiController |
| 43 | +{ |
| 44 | + use PaginatedResponseTrait; |
| 45 | + |
| 46 | + private const string ROUTE = '/search/saved/configuration'; |
| 47 | + |
| 48 | + public function __construct( |
| 49 | + SerializerInterface $serializer, |
| 50 | + private readonly SavedSearchConfigurationServiceInterface $savedSearchConfigurationService, |
| 51 | + ) { |
| 52 | + parent::__construct($serializer); |
| 53 | + } |
| 54 | + |
| 55 | + #[Route( |
| 56 | + self::ROUTE, |
| 57 | + name: 'pimcore_studio_api_get_saved_search_configurations', |
| 58 | + methods: ['GET'], |
| 59 | + )] |
| 60 | + #[IsGranted(UserPermissions::PIMCORE_USER->value)] |
| 61 | + #[Get( |
| 62 | + path: self::PREFIX . self::ROUTE, |
| 63 | + operationId: 'saved_search_get_configurations', |
| 64 | + description: 'saved_search_get_configurations_description', |
| 65 | + summary: 'saved_search_get_configurations_summary', |
| 66 | + tags: [Tags::Search->value] |
| 67 | + )] |
| 68 | + #[PageParameter] |
| 69 | + #[PageSizeParameter] |
| 70 | + #[TextFieldParameter( |
| 71 | + name: 'searchTerm', |
| 72 | + description: 'Optional term to filter the saved search configurations by name.', |
| 73 | + required: false |
| 74 | + )] |
| 75 | + #[SuccessResponse( |
| 76 | + description: 'saved_search_get_configurations_success_response', |
| 77 | + content: new CollectionJson(new GenericCollection(ConfigurationListItem::class)) |
| 78 | + )] |
| 79 | + #[DefaultResponses([ |
| 80 | + HttpResponseCodes::UNAUTHORIZED, |
| 81 | + ])] |
| 82 | + public function getSavedSearchConfigurations( |
| 83 | + #[MapQueryParameter] ?string $searchTerm = null, |
| 84 | + #[MapQueryString] CollectionParameters $parameters = new CollectionParameters(), |
| 85 | + ): JsonResponse { |
| 86 | + $collection = $this->savedSearchConfigurationService->listConfigurations( |
| 87 | + $parameters, |
| 88 | + $searchTerm |
| 89 | + ); |
| 90 | + |
| 91 | + return $this->getPaginatedCollection( |
| 92 | + $this->serializer, |
| 93 | + $collection->getItems(), |
| 94 | + $collection->getTotalItems() |
| 95 | + ); |
| 96 | + } |
| 97 | +} |
0 commit comments