Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use-interfaces-correct #33

Merged
merged 9 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Controller/Api/Assets/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\Parameters;
use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
Expand Down Expand Up @@ -85,7 +84,6 @@ public function __construct(
#[UnauthorizedResponse]
public function getAssets(#[MapQueryString] Parameters $parameters): JsonResponse
{
/** @var AssetQuery $assetQuery */
$assetQuery = $this->filterService->applyFilters(
$parameters,
FilterServiceInterface::TYPE_ASSET
Expand Down
2 changes: 0 additions & 2 deletions src/Controller/Api/DataObjects/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\DataObjectParameters;
use Pimcore\Bundle\StudioApiBundle\Service\DataObjectSearchServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
Expand Down Expand Up @@ -85,7 +84,6 @@ public function __construct(
public function getDataObjects(#[MapQueryString] DataObjectParameters $parameters): JsonResponse
{

/** @var DataObjectQuery $dataObjectQuery */
$dataObjectQuery = $this->filterService->applyFilters($parameters, 'dataObject');

$result = $this->dataObjectSearchService->searchDataObjects($dataObjectQuery);
Expand Down
23 changes: 23 additions & 0 deletions src/Exception/InvalidSearchException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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\StudioApiBundle\Exception;

use Exception;

final class InvalidSearchException extends Exception
{
}
4 changes: 2 additions & 2 deletions src/Service/AssetSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Unknown;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Video;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\AssetSearchAdapterInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

final readonly class AssetSearchService implements AssetSearchServiceInterface
{
public function __construct(private AssetSearchAdapterInterface $assetSearchAdapter)
{
}

public function searchAssets(AssetQuery $assetQuery): AssetSearchResult
public function searchAssets(QueryInterface $assetQuery): AssetSearchResult
{
return $this->assetSearchAdapter->searchAssets($assetQuery);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Service/AssetSearchServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Text;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Unknown;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Video;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

interface AssetSearchServiceInterface
{
public function searchAssets(AssetQuery $assetQuery): AssetSearchResult;
public function searchAssets(QueryInterface $assetQuery): AssetSearchResult;

public function getAssetById(int $id): Asset|Archive|Audio|Document|Folder|Image|Text|Unknown|Video|null;
}
4 changes: 2 additions & 2 deletions src/Service/DataObjectSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace Pimcore\Bundle\StudioApiBundle\Service;

use Pimcore\Bundle\StudioApiBundle\Service\GenericData\DataObjectSearchAdapterInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;
use Pimcore\Model\DataObject\Concrete;

final readonly class DataObjectSearchService implements DataObjectSearchServiceInterface
Expand All @@ -26,7 +26,7 @@ public function __construct(private DataObjectSearchAdapterInterface $dataObject
{
}

public function searchDataObjects(DataObjectQuery $dataObjectQuery): DataObjectSearchResult
public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSearchResult
{
return $this->dataObjectSearchAdapter->searchDataObjects($dataObjectQuery);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Service/DataObjectSearchServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

namespace Pimcore\Bundle\StudioApiBundle\Service;

use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;
use Pimcore\Model\DataObject\Concrete;

interface DataObjectSearchServiceInterface
{
public function searchDataObjects(DataObjectQuery $dataObjectQuery): DataObjectSearchResult;
public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSearchResult;

public function getDataObjectById(int $id): Concrete|null;
}
4 changes: 2 additions & 2 deletions src/Service/GenericData/AssetSearchAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

use Pimcore\Bundle\StudioApiBundle\Response\Asset;
use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchResult;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

interface AssetSearchAdapterInterface
{
public function searchAssets(AssetQuery $assetQuery): AssetSearchResult;
public function searchAssets(QueryInterface $assetQuery): AssetSearchResult;

public function getAssetById(int $id): ?Asset;
}
4 changes: 2 additions & 2 deletions src/Service/GenericData/DataObjectSearchAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
namespace Pimcore\Bundle\StudioApiBundle\Service\GenericData;

use Pimcore\Bundle\StudioApiBundle\Service\DataObjectSearchResult;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;
use Pimcore\Model\Element\ElementInterface;

interface DataObjectSearchAdapterInterface
{
public function searchDataObjects(DataObjectQuery $dataObjectQuery): DataObjectSearchResult;
public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSearchResult;

public function getDataObjectById(int $id): ?ElementInterface;
}
2 changes: 1 addition & 1 deletion src/Service/GenericData/V1/AssetQueryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(private SearchProviderInterface $searchProvider)
{
}

public function createAssetQuery(): AssetQuery
public function createAssetQuery(): QueryInterface
{
return new AssetQuery($this->searchProvider->createAssetSearch());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Service/GenericData/V1/AssetQueryProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

interface AssetQueryProviderInterface
{
public function createAssetQuery(): AssetQuery;
public function createAssetQuery(): QueryInterface;
}
2 changes: 1 addition & 1 deletion src/Service/GenericData/V1/AssetSearchAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
/**
* @throws Exception
*/
public function searchAssets(AssetQuery $assetQuery): AssetSearchResult
public function searchAssets(QueryInterface $assetQuery): AssetSearchResult
{
$searchResult = $this->searchService->search($assetQuery->getSearch());
$result = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Service/GenericData/V1/DataObjectQueryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
) {
}

public function createDataObjectQuery(): DataObjectQuery
public function createDataObjectQuery(): QueryInterface
{
/** @var DataObjectSearch $dataObjectSearch */
$dataObjectSearch = $this->searchProvider->createDataObjectSearch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

interface DataObjectQueryProviderInterface
{
public function createDataObjectQuery(): DataObjectQuery;
public function createDataObjectQuery(): QueryInterface;
}
20 changes: 18 additions & 2 deletions src/Service/GenericData/V1/DataObjectSearchAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

namespace Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\DataObjectSearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\DataObject\DataObjectSearchServiceInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolver;
use Pimcore\Bundle\StudioApiBundle\Exception\InvalidSearchException;
use Pimcore\Bundle\StudioApiBundle\Response\DataObject;
use Pimcore\Bundle\StudioApiBundle\Service\DataObjectSearchResult;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\DataObjectSearchAdapterInterface;
Expand All @@ -32,9 +34,23 @@ public function __construct(
) {
}

public function searchDataObjects(DataObjectQuery $dataObjectQuery): DataObjectSearchResult
/**
* @throws InvalidSearchException
*/
public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSearchResult
{
$searchResult = $this->searchService->search($dataObjectQuery->getSearch());

$search = $dataObjectQuery->getSearch();
if (!$search instanceof DataObjectSearchInterface) {
throw new InvalidSearchException(
sprintf(
'Expected search to be an instance of %s, got %s',
DataObjectSearchInterface::class,
get_class($search)
)
);
}
$searchResult = $this->searchService->search($search);
$result = [];
foreach($searchResult->getIds() as $id) {
/** @var Concrete $dataObject */
Expand Down
Loading