-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
604 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
# controllers are imported separately to make sure they're public | ||
# and have a tag that allows actions to type-hint services | ||
Pimcore\Bundle\StudioBackendBundle\Search\Controller\: | ||
resource: '../src/Search/Controller' | ||
public: true | ||
tags: [ 'controller.service_arguments' ] | ||
|
||
# | ||
# Hydrator | ||
# | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Search\Hydrator\SimpleSearchHydratorInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Search\Hydrator\SimpleSearchHydrator | ||
|
||
# | ||
# Repositories | ||
# | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Search\Repository\SearchRepositoryInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Search\Repository\SearchRepository | ||
|
||
# | ||
# Services | ||
# | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Search\Service\SearchServiceInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Search\Service\SearchService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Search\Controller; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageSizeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\TextFieldParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Search\MappedParameter\SimpleSearchParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Search\Schema\SimpleSearchResult; | ||
use Pimcore\Bundle\StudioBackendBundle\Search\Service\SearchServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapQueryString; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class SimpleController extends AbstractApiController | ||
{ | ||
use PaginatedResponseTrait; | ||
|
||
private const ROUTE = '/search'; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly SearchServiceInterface $searchService, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws SearchException|UserNotFoundException | ||
*/ | ||
#[Route(path: self::ROUTE, name: 'pimcore_studio_api_search', methods: ['GET'])] | ||
#[Get( | ||
path: self::PREFIX . self::ROUTE, | ||
operationId: 'simple_search_get', | ||
description: 'simple_search_get_description', | ||
summary: 'simple_search_get_summary', | ||
tags: [Tags::Search->name] | ||
)] | ||
#[PageParameter] | ||
#[PageSizeParameter] | ||
#[TextFieldParameter(name: 'searchTerm', description: 'simple_search_get_search_term_parameter', required: false)] | ||
#[SuccessResponse( | ||
description: 'simple_search_get_success_response', | ||
content: new CollectionJson(new GenericCollection(SimpleSearchResult::class)) | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::BAD_REQUEST, | ||
])] | ||
public function doSimpleSearch(#[MapQueryString] SimpleSearchParameter $parameters): JsonResponse | ||
{ | ||
$collection = $this->searchService->doSimpleSearch($parameters); | ||
|
||
return $this->getPaginatedCollection( | ||
$this->serializer, | ||
$collection->getItems(), | ||
$collection->getTotalItems() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Search\Event\PreResponse; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Element\Schema\CustomAttributes; | ||
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; | ||
use Pimcore\Bundle\StudioBackendBundle\Search\Schema\SimpleSearchResult; | ||
|
||
final class SimpleSearchResultEvent extends AbstractPreResponseEvent | ||
{ | ||
public const EVENT_NAME = 'pre_response.simple_search.result'; | ||
|
||
public function __construct(private readonly SimpleSearchResult $result) | ||
{ | ||
parent::__construct($this->result); | ||
} | ||
|
||
public function getSimpleSearchResult(): SimpleSearchResult | ||
{ | ||
return $this->result; | ||
} | ||
|
||
public function getCustomAttributes(): ?CustomAttributes | ||
{ | ||
return $this->result->getCustomAttributes(); | ||
} | ||
|
||
public function setCustomAttributes(CustomAttributes $customAttributes): void | ||
{ | ||
$this->result->setCustomAttributes($customAttributes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Search\Hydrator; | ||
|
||
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Icon\Service\IconServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Search\Schema\SimpleSearchResult; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class SimpleSearchHydrator implements SimpleSearchHydratorInterface | ||
{ | ||
use ElementProviderTrait; | ||
|
||
public function __construct( | ||
private IconServiceInterface $iconService | ||
) { | ||
} | ||
|
||
public function hydrate(ElementSearchResultItemInterface $resultItem): SimpleSearchResult | ||
{ | ||
return new SimpleSearchResult( | ||
$resultItem->getId(), | ||
$resultItem->getElementType()->value, | ||
$resultItem->getType(), | ||
$resultItem->getFullPath(), | ||
$this->iconService->getIconForElement($resultItem) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Search\Hydrator; | ||
|
||
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Search\Schema\SimpleSearchResult; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface SimpleSearchHydratorInterface | ||
{ | ||
public function hydrate(ElementSearchResultItemInterface $resultItem): SimpleSearchResult; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Search\MappedParameter; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParameters; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class SimpleSearchParameter extends CollectionParameters | ||
{ | ||
public function __construct( | ||
int $page = 1, | ||
int $pageSize = 50, | ||
private ?string $searchTerm = null, | ||
) { | ||
parent::__construct($page, $pageSize); | ||
} | ||
|
||
public function getSearchTerm(): ?string | ||
{ | ||
return $this->searchTerm; | ||
} | ||
|
||
} |
Oops, something went wrong.