Skip to content

Commit

Permalink
Update, add put, delete etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed May 7, 2024
1 parent de76a32 commit 70b7668
Show file tree
Hide file tree
Showing 24 changed files with 657 additions and 36 deletions.
8 changes: 8 additions & 0 deletions config/properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorService

Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyService

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

Expand All @@ -27,3 +30,8 @@ services:

Pimcore\Bundle\StudioBackendBundle\Property\Extractor\PropertyDataExtractorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Property\Extractor\PropertyDataExtractor

Pimcore\Bundle\StudioBackendBundle\Property\Factory\PropertyFactoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Property\Factory\PropertyFactory


31 changes: 31 additions & 0 deletions src/Exception/NotWriteableException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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\Exception;

/**
* @internal
*/
final class NotWriteableException extends AbstractApiException
{
public function __construct(string $type)
{
parent::__construct(500, sprintf(
'Cannot create: %s',
$type
));
}
}
28 changes: 28 additions & 0 deletions src/Exception/PropertyNotFoundException.php
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\Exception;

/**
* @internal
*/
final class PropertyNotFoundException extends AbstractApiException
{
public function __construct(string $id)
{
parent::__construct(404, 'Property with ID ' . $id . ' not found');
}
}
4 changes: 2 additions & 2 deletions src/OpenApi/Attributes/Parameters/Path/IdParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
#[Attribute(Attribute::TARGET_METHOD)]
final class IdParameter extends PathParameter
{
public function __construct(string $type = 'element')
public function __construct(string $type = 'element', Schema $schema = new Schema(type: 'integer', example: 83))
{
parent::__construct(
name: 'id',
description: 'ID of the ' . $type,
in: 'path',
required: true,
schema: new Schema(type: 'integer', example: 83),
schema: $schema,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
#[Attribute(Attribute::TARGET_METHOD)]
final class ElementTypeParameter extends QueryParameter
{
public function __construct()
public function __construct(bool $required = true, ?string $example = ElementTypes::TYPE_DATA_OBJECT)
{
parent::__construct(
name: 'elementType',
description: 'Filter elements by matching element type.',
in: 'query',
required: true,
required: $required,
schema: new Schema(
type: 'string',
enum: [
ElementTypes::TYPE_ASSET,
ElementTypes::TYPE_DOCUMENT,
ElementTypes::TYPE_DATA_OBJECT,
],
example: ElementTypes::TYPE_DATA_OBJECT,
example: $example,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
use OpenApi\Attributes\Schema;

#[Attribute(Attribute::TARGET_METHOD)]
final class QueryParameter extends OpenApiQueryParameter
final class FilterParameter extends OpenApiQueryParameter
{
public function __construct()
{
parent::__construct(
name: 'query',
description: 'Query for properties',
in: 'query',
name: 'filter',
description: 'Filter for properties',
in: 'filter',
required: false,
schema: new Schema(type: 'string', example: null),
);
Expand Down
34 changes: 34 additions & 0 deletions src/OpenApi/Attributes/Request/PropertyRequestBody.php
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\OpenApi\Attributes\Request;

use Attribute;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\Property\Schema\UpdatePredefinedProperty;

#[Attribute(Attribute::TARGET_METHOD)]
final class PropertyRequestBody extends RequestBody
{
public function __construct()
{
parent::__construct(
required: true,
content: new JsonContent(ref: UpdatePredefinedProperty::class)
);
}
}
15 changes: 7 additions & 8 deletions src/Property/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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\Parameters\Query\QueryParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\FilterParameter;
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;
Expand Down Expand Up @@ -57,26 +57,25 @@ public function __construct(
*/
#[Route('/properties', name: 'pimcore_studio_api_properties', methods: ['GET'])]
//#[IsGranted('STUDIO_API')]
#[GET(
#[Get(
path: self::API_PATH . '/properties',
operationId: 'getProperties',
description: 'Get paginated predefined properties',
summary: 'Get all properties for element type',
summary: 'Get all predefined properties. You can filter by type and query',
security: self::SECURITY_SCHEME,
tags: [Tags::Properties->name]
)]
#[ElementTypeParameter]
#[QueryParameter]
#[ElementTypeParameter(false, null)]
#[FilterParameter]
#[SuccessResponse(
description: 'Predefined properties based on type and query parameters',
description: 'Predefined properties filtered based on type and query parameters',
content: new ItemsJson(PredefinedProperty::class)
)]
#[BadRequestResponse]
#[UnauthorizedResponse]
#[MethodNotAllowedResponse]
#[UnsupportedMediaTypeResponse]
#[UnprocessableContentResponse]
public function getProperties(#[MapQueryString] PropertiesParameters $parameters): JsonResponse
public function getProperties(#[MapQueryString] PropertiesParameters $parameters = new PropertiesParameters()): JsonResponse

Check warning on line 78 in src/Property/Controller/CollectionController.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

Check warning on line 78 in src/Property/Controller/CollectionController.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)
{
return $this->jsonResponse(['items' => $this->hydratorService->getHydratedProperties($parameters)]);
}
Expand Down
69 changes: 69 additions & 0 deletions src/Property/Controller/CreateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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\JsonContent;
use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
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\Factory\PropertyFactoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Property\Schema\PredefinedProperty;
use Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorServiceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;

final class CreateController extends AbstractApiController
{
public function __construct(
SerializerInterface $serializer,
private readonly PropertyFactoryInterface $propertyFactory,
private readonly PropertyHydratorServiceInterface $hydratorService,
)
{
parent::__construct($serializer);
}

#[Route('/property', name: 'pimcore_studio_api_create_property', methods: ['POST'])]
#[POST(
path: self::API_PATH . '/property',
operationId: 'createProperty',
summary: 'Creating new property with default values',
security: self::SECURITY_SCHEME,
tags: [Tags::Properties->name]
)]
#[SuccessResponse(
description: 'Element Properties data as json',
content: new JsonContent(ref: PredefinedProperty::class, type: 'object')
)]
#[BadRequestResponse]
#[UnauthorizedResponse]
#[MethodNotAllowedResponse]
#[UnsupportedMediaTypeResponse]
#[UnprocessableContentResponse]
public function createProperty(): JsonResponse
{
$property = $this->propertyFactory->create();
return $this->jsonResponse($this->hydratorService->getHydratedPredefinedProperty($property));
}
}
73 changes: 73 additions & 0 deletions src/Property/Controller/DeleteController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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\Delete;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\ItemsJson;
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 Pimcore\Bundle\StudioBackendBundle\Property\Schema\DataProperty;
use Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyServiceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class DeleteController extends AbstractApiController
{
public function __construct(
private readonly PropertyServiceInterface $propertyService,
SerializerInterface $serializer,
) {
parent::__construct($serializer);
}

#[Route('/properties/{id}', name: 'pimcore_studio_api_delete_properties', methods: ['DELETE'])]
//#[IsGranted('STUDIO_API')]
#[Delete(
path: self::API_PATH . '/properties/{id}',
operationId: 'deleteProperty',
summary: 'Delete property with given id',
security: self::SECURITY_SCHEME,
tags: [Tags::Properties->name]
)]
#[IdParameter(type: 'property', schema: new Schema(type: 'string', example: 'alpha-numerical'))]
#[SuccessResponse(
description: 'Element Properties data as json',
content: new ItemsJson(DataProperty::class)
)]
#[UnauthorizedResponse]
#[NotFoundResponse]
#[MethodNotAllowedResponse]
#[UnsupportedMediaTypeResponse]
#[UnprocessableContentResponse]
public function deleteProperty(string $id): JsonResponse
{
$this->propertyService->deletePredefinedProperty($id);
return $this->jsonResponse(['id' => $id]);
}
}
9 changes: 4 additions & 5 deletions src/Property/Controller/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
namespace Pimcore\Bundle\StudioBackendBundle\Property\Controller;

use OpenApi\Attributes\Get;
use OpenApi\Attributes\JsonContent;
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\ItemsJson;
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;
Expand Down Expand Up @@ -48,19 +48,18 @@ public function __construct(

#[Route('/properties/{elementType}/{id}', name: 'pimcore_studio_api_get_properties', methods: ['GET'])]
//#[IsGranted('STUDIO_API')]
#[GET(
#[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',
summary: 'Get properties for an element based on the element type and the element id',
security: self::SECURITY_SCHEME,
tags: [Tags::Properties->name]
)]
#[ElementTypeParameter]
#[IdParameter(type: 'element')]
#[SuccessResponse(
description: 'Element Properties data as json',
content: new JsonContent(ref: DataProperty::class, type: 'object')
content: new ItemsJson(DataProperty::class)
)]
#[UnauthorizedResponse]
#[NotFoundResponse]
Expand Down
Loading

0 comments on commit 70b7668

Please sign in to comment.