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

[Data Object Editor] Quantity value endpoints tag handling #619

Merged
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
6 changes: 0 additions & 6 deletions config/class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ services:
Pimcore\Bundle\StudioBackendBundle\Class\Service\ObjectBrick\LayoutDefinitionServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\ObjectBrick\LayoutDefinitionService

Pimcore\Bundle\StudioBackendBundle\Class\Repository\QuantityValueRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Repository\QuantityValueRepository

Pimcore\Bundle\StudioBackendBundle\Class\Service\QuantityValueServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\QuantityValueService

#
# Hydrators
#
Expand Down
26 changes: 26 additions & 0 deletions config/units.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\Unit\Controller\:
resource: '../src/Unit/Controller'
public: true
tags: [ 'controller.service_arguments' ]

#
# Services
#

Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueService

#
# Repositories
#

Pimcore\Bundle\StudioBackendBundle\Unit\Repository\QuantityValueRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Unit\Repository\QuantityValueRepository
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use OpenApi\Attributes\QueryParameter;
use OpenApi\Attributes\Schema;

#[Attribute(Attribute::TARGET_METHOD)]
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class TextFieldParameter extends QueryParameter
{
public function __construct(string $name, string $description, bool $required = false, string $example = null)
Expand Down
5 changes: 5 additions & 0 deletions src/OpenApi/Config/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
name: Tags::Translation->value,
description: 'tag_translation_description'
)]
#[Tag(
name: Tags::Units->value,
description: 'tag_units_description'
)]
#[Tag(
name: Tags::User->value,
description: 'tag_user_description'
Expand Down Expand Up @@ -150,6 +154,7 @@ enum Tags: string
case Tags = 'Tags';
case TagsForElement = 'Tags for Element';
case Translation = 'Translation';
case Units = 'Units';
case User = 'User Management';
case Versions = 'Versions';
case Workflows = 'Workflows';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,29 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Request;
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Attribute\Parameter\Query;

use Attribute;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertParameters;
use OpenApi\Attributes\QueryParameter;
use OpenApi\Attributes\Schema;

#[Attribute(Attribute::TARGET_METHOD)]
final class ConvertRequestBody extends RequestBody
final class ValueParameter extends QueryParameter
{
public function __construct(string $ref = ConvertParameters::class)
public function __construct()
{
parent::__construct(
name: 'value',
description: 'Value to convert.',
in: 'query',
required: true,
content: new JsonContent(ref: $ref)
schema: new Schema(
anyOf: [
new Schema(type: 'integer', format: 'int32'),
new Schema(type: 'number', format: 'float'),
],
),
example: 5
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Response;
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Attribute\Response;

use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Response;
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Attribute\Response;

use OpenApi\Attributes\Items;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\QuantityValueUnit;
use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\QuantityValueUnit;

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\QuantityValue;
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Controller\QuantityValue;

use OpenApi\Attributes\Get;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Request\ConvertRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertAllParameters;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertedQuantityValues;
use Pimcore\Bundle\StudioBackendBundle\Class\Service\QuantityValueServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\TextFieldParameter;
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\Unit\Attribute\Parameter\Query\ValueParameter;
use Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter\ConvertAllUnitsParameter;
use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\ConvertedQuantityValues;
use Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;
Expand All @@ -56,28 +57,34 @@ public function __construct(
* @throws DatabaseException|NotFoundException
*/
#[Route(
'/class/quantity-value/convert-all',
name: 'pimcore_studio_api_get_class_quantity_value_convert_all',
methods: ['POST']
'/unit/quantity-value/convert-all',
name: 'pimcore_studio_api_unit_quantity_value_convert_all',
methods: ['GET']
)]
#[IsGranted(UserPermissions::DATA_OBJECTS->value)]
#[Post(
path: self::PREFIX . '/class/quantity-value/convert-all',
operationId: 'class_quantity_value_unit_convert_all',
description: 'class_quantity_value_unit_convert_all_description',
summary: 'class_quantity_value_unit_convert_all_summary',
tags: [Tags::ClassDefinition->value]
#[Get(
path: self::PREFIX . '/unit/quantity-value/convert-all',
operationId: 'unit_quantity_value_convert_all',
description: 'unit_quantity_value_convert_all_description',
summary: 'unit_quantity_value_convert_all_summary',
tags: [Tags::Units->value]
)]
#[TextFieldParameter(
name: 'fromUnitId',
description: 'Id of the unit to convert from',
required: true
)]
#[ValueParameter]
#[SuccessResponse(
description: 'class_quantity_value_unit_convert_all_success_response',
description: 'unit_quantity_value_convert_all_success_response',
content: new JsonContent(ref: ConvertedQuantityValues::class)
)]
#[ConvertRequestBody(ConvertAllParameters::class)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND,
HttpResponseCodes::INTERNAL_SERVER_ERROR,
])]
public function covertAll(#[MapRequestPayload] ConvertAllParameters $parameters): JsonResponse
public function covertAll(#[MapQueryString] ConvertAllUnitsParameter $parameters): JsonResponse
{
return $this->jsonResponse($this->quantityValueService->convertAllUnits($parameters));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\QuantityValue;
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Controller\QuantityValue;

use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Request\ConvertRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Response\ConvertedValueJson;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertParameters;
use Pimcore\Bundle\StudioBackendBundle\Class\Service\QuantityValueServiceInterface;
use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\TextFieldParameter;
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\Unit\Attribute\Parameter\Query\ValueParameter;
use Pimcore\Bundle\StudioBackendBundle\Unit\Attribute\Response\ConvertedValueJson;
use Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter\ConvertUnitParameter;
use Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;
Expand All @@ -55,28 +56,39 @@ public function __construct(
* @throws DatabaseException|NotFoundException
*/
#[Route(
'/class/quantity-value/convert',
name: 'pimcore_studio_api_get_class_quantity_value_convert',
methods: ['POST']
'/unit/quantity-value/convert',
name: 'pimcore_studio_api_unit_quantity_value_convert',
methods: ['GET']
)]
#[IsGranted(UserPermissions::DATA_OBJECTS->value)]
#[Post(
path: self::PREFIX . '/class/quantity-value/convert',
operationId: 'class_quantity_value_unit_convert',
description: 'class_quantity_value_unit_convert_description',
summary: 'class_quantity_value_unit_convert_summary',
tags: [Tags::ClassDefinition->value]
#[Get(
path: self::PREFIX . '/unit/quantity-value/convert',
operationId: 'unit_quantity_value_convert',
description: 'unit_quantity_value_convert_description',
summary: 'unit_quantity_value_convert_summary',
tags: [Tags::Units->value]
)]
#[TextFieldParameter(
name: 'fromUnitId',
description: 'Id of the unit to convert from',
required: true
)]
#[TextFieldParameter(
name: 'toUnitId',
description: 'Id of the unit to convert to',
required: true
)]
#[ValueParameter]
#[SuccessResponse(
description: 'class_quantity_value_unit_convert_success_response',
description: 'unit_quantity_value_convert_success_response',
content: new ConvertedValueJson()
)]
#[ConvertRequestBody]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND,
HttpResponseCodes::INTERNAL_SERVER_ERROR,
])]
public function convert(#[MapRequestPayload] ConvertParameters $parameters): JsonResponse
public function convert(#[MapQueryString] ConvertUnitParameter $parameters): JsonResponse
{
return $this->jsonResponse(['data' => $this->quantityValueService->convertUnit($parameters)]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\QuantityValue;
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Controller\QuantityValue;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Response\QuantityValueUnitsJson;
use Pimcore\Bundle\StudioBackendBundle\Class\Service\QuantityValueServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
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\Unit\Attribute\Response\QuantityValueUnitsJson;
use Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait;
Expand All @@ -47,20 +47,20 @@ public function __construct(
}

#[Route(
'/class/quantity-value/unit-list',
name: 'pimcore_studio_api_get_class_quantity_value_unit_list',
'/unit/quantity-value/unit-list',
name: 'pimcore_studio_api_unit_quantity_value_list',
methods: ['GET']
)]
#[IsGranted(UserPermissions::DATA_OBJECTS->value)]
#[Get(
path: self::PREFIX . '/class/quantity-value/unit-list',
operationId: 'class_quantity_value_unit_list',
description: 'class_quantity_value_unit_list_description',
summary: 'class_quantity_value_unit_list_summary',
tags: [Tags::ClassDefinition->value]
path: self::PREFIX . '/unit/quantity-value/unit-list',
operationId: 'unit_quantity_value_list',
description: 'unit_quantity_value_list_description',
summary: 'unit_quantity_value_list_summary',
tags: [Tags::Units->value]
)]
#[SuccessResponse(
description: 'class_quantity_value_unit_list_success_response',
description: 'unit_quantity_value_list_success_response',
content: new QuantityValueUnitsJson()
)]
#[DefaultResponses([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Event\PreResponse;
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Event\PreResponse;

use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertedQuantityValues;
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\ConvertedQuantityValues;

final class QuantityValueConversionEvent extends AbstractPreResponseEvent
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Event\PreResponse;
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Event\PreResponse;

use Pimcore\Bundle\StudioBackendBundle\Class\Schema\QuantityValueUnit;
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\QuantityValueUnit;

final class QuantityValueUnitEvent extends AbstractPreResponseEvent
{
Expand Down
Loading
Loading