Skip to content

Commit

Permalink
WIP: add properties controller, hydradtors, services etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed May 2, 2024
1 parent 9bbb0ce commit 7dbf13a
Show file tree
Hide file tree
Showing 19 changed files with 815 additions and 0 deletions.
26 changes: 26 additions & 0 deletions config/properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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\Property\Controller\:
resource: '../src/Property/Controller'
public: true
tags: [ 'controller.service_arguments' ]


Pimcore\Bundle\StudioBackendBundle\Property\RepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Property\Repository


Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorService

Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\DataPropertyHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\DataPropertyHydrator

Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\PredefinedPropertyHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\PredefinedPropertyHydrator
1 change: 1 addition & 0 deletions src/DependencyInjection/PimcoreStudioBackendExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('filters.yaml');
$loader->load('icon.yaml');
$loader->load('open_api.yaml');
$loader->load('properties.yaml');
$loader->load('security.yaml');
$loader->load('services.yaml');
$loader->load('translation.yaml');
Expand Down
45 changes: 45 additions & 0 deletions src/OpenApi/Attributes/Parameters/Path/ElementTypeParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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\OpenApi\Attributes\Parameters\Path;

use Attribute;
use OpenApi\Attributes\PathParameter;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes;

#[Attribute(Attribute::TARGET_METHOD)]
final class ElementTypeParameter extends PathParameter
{
public function __construct()
{
parent::__construct(
name: 'elementType',
description: 'Filter elements by matching element type.',
in: 'path',
required: true,
schema: new Schema(
type: 'string',
enum: [
ElementTypes::TYPE_ASSET,
ElementTypes::TYPE_DOCUMENT,
ElementTypes::TYPE_DATA_OBJECT,
],
example: ElementTypes::TYPE_DATA_OBJECT,
),
);
}
}
37 changes: 37 additions & 0 deletions src/OpenApi/Attributes/Parameters/Query/QueryParameter.php
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\OpenApi\Attributes\Parameters\Query;

use Attribute;
use OpenApi\Attributes\QueryParameter as OpenApiQueryParameter;
use OpenApi\Attributes\Schema;
use Pimcore\Model\DataObject\ClassDefinition;

#[Attribute(Attribute::TARGET_METHOD)]
final class QueryParameter extends OpenApiQueryParameter
{
public function __construct()
{
parent::__construct(
name: 'query',
description: 'Query for properties',
in: 'query',
required: false,
schema: new Schema(type: 'string', example: null),
);
}
}
38 changes: 38 additions & 0 deletions src/OpenApi/Attributes/Response/Content/ItemsJson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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\OpenApi\Attributes\Response\Content;

use OpenApi\Attributes\Items;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
use Pimcore\Bundle\StudioBackendBundle\Property\Schema\PredefinedProperty as PropertySchema;

/**
* @internal
*/
final class ItemsJson extends JsonContent
{
public function __construct(string $schema)
{
parent::__construct(
properties: [
new Property('items', type: 'array', items: new Items(ref:$schema))
],
type: 'object',
);
}
}
5 changes: 5 additions & 0 deletions src/OpenApi/Config/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
name: Tags::DataObjects->name,
description: 'DataObject operations to get/update/create/delete data objects'
)]
#[Tag(
name: Tags::Properties->name,
description: 'Get properties for elements'
)]
#[Tag(
name: Tags::Translation->name,
description: 'Get translations either for a single key or multiple keys'
Expand All @@ -46,6 +50,7 @@ enum Tags
case Assets;
case Authorization;
case DataObjects;
case Properties;
case Translation;
case Versions;
}
81 changes: 81 additions & 0 deletions src/Property/Controller/CollectionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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\Property\Controller;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\InvalidQueryTypeException;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\ElementTypeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\ItemsJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\BadRequestResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnauthorizedResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnsupportedMediaTypeResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Property\Request\PropertiesParameters;
use Pimcore\Bundle\StudioBackendBundle\Property\Schema\PredefinedProperty;
use Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\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 CollectionController extends AbstractApiController

Check notice on line 43 in src/Property/Controller/CollectionController.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Efferent coupling between objects

\[EA\] High efferent coupling (20).
{
use PaginatedResponseTrait;

public function __construct(
SerializerInterface $serializer,
private readonly PropertyHydratorServiceInterface $hydratorService,
) {
parent::__construct($serializer);
}

/**
* @throws InvalidQueryTypeException
*/
#[Route('/properties', name: 'pimcore_studio_api_properties', methods: ['GET'])]
//#[IsGranted('STUDIO_API')]
#[GET(
path: self::API_PATH . '/properties',
operationId: 'getProperties',
description: 'Get paginated predefined properties',
summary: 'Get all properties for element type',
security: self::SECURITY_SCHEME,
tags: [Tags::Properties->name]
)]
#[ElementTypeParameter]
#[SuccessResponse(
description: 'Paginated properties with total count as header param',
content: new ItemsJson(PredefinedProperty::class)
)]
#[BadRequestResponse]
#[UnauthorizedResponse]
#[MethodNotAllowedResponse]
#[UnsupportedMediaTypeResponse]
#[UnprocessableContentResponse]
public function getProperties(#[MapQueryString] PropertiesParameters $parameters): JsonResponse
{
return $this->jsonResponse($this->hydratorService->getHydratedProperties($parameters));
}
}
72 changes: 72 additions & 0 deletions src/Property/Controller/GetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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\Property\Controller;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\ElementTypeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\OneOfVersionJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\NotFoundResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnauthorizedResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnsupportedMediaTypeResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class GetController extends AbstractApiController
{
public function __construct(

Check notice on line 40 in src/Property/Controller/GetController.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Senseless proxy function

\[EA\] '__construct' method can be dropped, as it only calls parent's one.
SerializerInterface $serializer,
) {
parent::__construct($serializer);
}

#[Route('/properties/{elementType}/{id}', name: 'pimcore_studio_api_get_properties', methods: ['GET'])]
//#[IsGranted('STUDIO_API')]
#[GET(
path: self::API_PATH . '/properties/{elementType}/{id}',
operationId: 'getPropertiesByTypeAndId',
description: 'Get properties based on the type and the id',
summary: 'Get properties by type and ID',
security: self::SECURITY_SCHEME,
tags: [Tags::Properties->name]
)]
#[IdParameter(type: 'element')]
#[ElementTypeParameter]
#[SuccessResponse(
description: 'Version data as json',
content: new OneOfVersionJson()
)]
#[UnauthorizedResponse]
#[NotFoundResponse]
#[MethodNotAllowedResponse]
#[UnsupportedMediaTypeResponse]
#[UnprocessableContentResponse]
public function getProperties(string $elementType, int $id): JsonResponse

Check notice on line 67 in src/Property/Controller/GetController.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unused parameter

Unused parameter 'elementType'. The parameter's value is not used anywhere.

Check notice on line 67 in src/Property/Controller/GetController.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unused parameter

Unused parameter 'id'. The parameter's value is not used anywhere.
{

return $this->jsonResponse([]);
}
}
Loading

0 comments on commit 7dbf13a

Please sign in to comment.