-
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.
[Documents] Get Available Sites endpoint (#595)
* feat: add endpoint to list available sites * Apply php-cs-fixer changes * fix: sonar * apply review feedback * Apply php-cs-fixer changes * fix: renaming issue --------- Co-authored-by: lukmzig <[email protected]>
- Loading branch information
Showing
16 changed files
with
569 additions
and
3 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
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,43 @@ | ||
<?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\Document\Attribute\Response; | ||
|
||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\Property; | ||
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Site; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class AvailableSitesJson extends JsonContent | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: ['items'], | ||
properties: [ | ||
new Property( | ||
'items', | ||
type: 'array', | ||
items: new Items(ref: Site::class) | ||
), | ||
], | ||
type: 'object', | ||
); | ||
} | ||
} |
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,74 @@ | ||
<?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\Document\Controller; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Document\Attribute\Response\AvailableSitesJson; | ||
use Pimcore\Bundle\StudioBackendBundle\Document\MappedParameter\ExcludeMainSiteParameter as MappedParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Document\OpenApi\Attribute\Parameter\Query\ExcludeMainSiteParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Document\Service\SiteServiceInterface; | ||
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\Util\Constant\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapQueryString; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class AvailableSitesController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
private readonly SiteServiceInterface $siteService, | ||
SerializerInterface $serializer | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
#[Route( | ||
'/documents/sites/list-available', | ||
name: 'pimcore_studio_api_sites_list_available', | ||
methods: ['GET'] | ||
)] | ||
#[IsGranted(UserPermissions::DOCUMENTS->value)] | ||
#[Get( | ||
path: self::PREFIX . '/documents/sites/list-available', | ||
operationId: 'documents_list_available_sites', | ||
description: 'documents_list_available_sites_description', | ||
summary: 'documents_list_available_sites_summary', | ||
tags: [Tags::Documents->value] | ||
)] | ||
#[ExcludeMainSiteParameter] | ||
#[SuccessResponse( | ||
description: 'documents_list_available_sites_success_response', | ||
content: new AvailableSitesJson() | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
])] | ||
public function getAvailableSites( | ||
#[MapQueryString] MappedParameter $parameter | ||
): JsonResponse { | ||
return $this->jsonResponse(['items' => $this->siteService->getAvailableSites($parameter)]); | ||
} | ||
} |
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,39 @@ | ||
<?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\Document\Event\PreResponse; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Site; | ||
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; | ||
|
||
final class SiteEvent extends AbstractPreResponseEvent | ||
{ | ||
public const EVENT_NAME = 'pre_response.document.sites_list_available'; | ||
|
||
public function __construct( | ||
private readonly Site $site | ||
) { | ||
parent::__construct($site); | ||
} | ||
|
||
/** | ||
* Use this to get additional infos out of the response object | ||
*/ | ||
public function getSite(): Site | ||
{ | ||
return $this->site; | ||
} | ||
} |
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,37 @@ | ||
<?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\Document\Hydrator; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Site; | ||
use Pimcore\Model\Site as SiteModel; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class SiteHydrator implements SiteHydratorInterface | ||
{ | ||
public function hydrate(SiteModel $siteModel): Site | ||
{ | ||
return new Site( | ||
$siteModel->getId(), | ||
$siteModel->getDomains(), | ||
$siteModel->getMainDomain(), | ||
$siteModel->getRootId(), | ||
$siteModel->getRootPath(), | ||
); | ||
} | ||
} |
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\Document\Hydrator; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Site; | ||
use Pimcore\Model\Site as SiteModel; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface SiteHydratorInterface | ||
{ | ||
public function hydrate(SiteModel $siteModel): Site; | ||
} |
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 @@ | ||
<?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\Document\MappedParameter; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class ExcludeMainSiteParameter | ||
{ | ||
public function __construct( | ||
private ?string $excludeMainSite = null | ||
) { | ||
} | ||
|
||
public function getExcludeMainSite(): bool | ||
{ | ||
return $this->excludeMainSite === 'true'; // TODO: symfony 7.1 will support bool type | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Document/OpenApi/Attribute/Parameter/Query/ExcludeMainSiteParameter.php
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,35 @@ | ||
<?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\Document\OpenApi\Attribute\Parameter\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class ExcludeMainSiteParameter extends QueryParameter | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
name: 'excludeMainSite', | ||
description: 'Exclude main site from the list', | ||
in: 'query', | ||
schema: new Schema(type: 'boolean', example: false), | ||
); | ||
} | ||
} |
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,34 @@ | ||
<?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\Document\Repository; | ||
|
||
use Pimcore\Model\Site; | ||
use Pimcore\Model\Site\Listing; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class SiteRepository implements SiteRepositoryInterface | ||
{ | ||
/** | ||
* @return Site[] | ||
*/ | ||
public function listSites(): array | ||
{ | ||
return (new Listing())->load(); | ||
} | ||
} |
Oops, something went wrong.