From d15a9d81f72f542d6f809d1affa201f848dd9dfc Mon Sep 17 00:00:00 2001 From: lukmzig <30526586+lukmzig@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:03:59 +0100 Subject: [PATCH] [Data Object Editor] Quantity value endpoints tag handling (#619) * add quantity value changes * Apply php-cs-fixer changes * remove unused request class --------- Co-authored-by: lukmzig --- config/class.yaml | 6 --- config/units.yaml | 26 ++++++++++ .../Parameter/Query/TextFieldParameter.php | 2 +- src/OpenApi/Config/Tags.php | 5 ++ .../Parameter/Query/ValueParameter.php} | 22 +++++--- .../Attribute/Response/ConvertedValueJson.php | 2 +- .../Response/QuantityValueUnitsJson.php | 4 +- .../QuantityValue/ConvertAllController.php | 45 ++++++++++------- .../QuantityValue/ConvertController.php | 50 ++++++++++++------- .../QuantityValue/UnitListController.php | 22 ++++---- .../QuantityValueConversionEvent.php | 4 +- .../PreResponse/QuantityValueUnitEvent.php | 4 +- .../ConvertAllUnitsParameter.php} | 19 +++---- .../MappedParameter/ConvertUnitParameter.php | 50 +++++++++++++++++++ .../Repository/QuantityValueRepository.php | 2 +- .../QuantityValueRepositoryInterface.php | 2 +- .../Schema/ConvertParameters.php | 2 +- .../Schema/ConvertedQuantityValue.php | 2 +- .../Schema/ConvertedQuantityValues.php | 2 +- .../Schema/QuantityValueUnit.php | 2 +- .../Service/QuantityValueService.php | 22 ++++---- .../Service/QuantityValueServiceInterface.php | 14 +++--- translations/studio_api_docs.en.yaml | 19 +++---- 23 files changed, 214 insertions(+), 114 deletions(-) create mode 100644 config/units.yaml rename src/{Class/Attribute/Request/ConvertRequestBody.php => Unit/Attribute/Parameter/Query/ValueParameter.php} (51%) rename src/{Class => Unit}/Attribute/Response/ConvertedValueJson.php (93%) rename src/{Class => Unit}/Attribute/Response/QuantityValueUnitsJson.php (87%) rename src/{Class => Unit}/Controller/QuantityValue/ConvertAllController.php (60%) rename src/{Class => Unit}/Controller/QuantityValue/ConvertController.php (58%) rename src/{Class => Unit}/Controller/QuantityValue/UnitListController.php (72%) rename src/{Class => Unit}/Event/PreResponse/QuantityValueConversionEvent.php (87%) rename src/{Class => Unit}/Event/PreResponse/QuantityValueUnitEvent.php (87%) rename src/{Class/Schema/ConvertAllParameters.php => Unit/MappedParameter/ConvertAllUnitsParameter.php} (61%) create mode 100644 src/Unit/MappedParameter/ConvertUnitParameter.php rename src/{Class => Unit}/Repository/QuantityValueRepository.php (95%) rename src/{Class => Unit}/Repository/QuantityValueRepositoryInterface.php (92%) rename src/{Class => Unit}/Schema/ConvertParameters.php (95%) rename src/{Class => Unit}/Schema/ConvertedQuantityValue.php (96%) rename src/{Class => Unit}/Schema/ConvertedQuantityValues.php (96%) rename src/{Class => Unit}/Schema/QuantityValueUnit.php (98%) rename src/{Class => Unit}/Service/QuantityValueService.php (83%) rename src/{Class => Unit}/Service/QuantityValueServiceInterface.php (61%) diff --git a/config/class.yaml b/config/class.yaml index 3cd25c3ca..ca87f087c 100644 --- a/config/class.yaml +++ b/config/class.yaml @@ -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 # diff --git a/config/units.yaml b/config/units.yaml new file mode 100644 index 000000000..d1f46a265 --- /dev/null +++ b/config/units.yaml @@ -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 \ No newline at end of file diff --git a/src/OpenApi/Attribute/Parameter/Query/TextFieldParameter.php b/src/OpenApi/Attribute/Parameter/Query/TextFieldParameter.php index 5b4553ad6..03d00023b 100644 --- a/src/OpenApi/Attribute/Parameter/Query/TextFieldParameter.php +++ b/src/OpenApi/Attribute/Parameter/Query/TextFieldParameter.php @@ -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) diff --git a/src/OpenApi/Config/Tags.php b/src/OpenApi/Config/Tags.php index 80c36f4a7..8d1fbcbbc 100644 --- a/src/OpenApi/Config/Tags.php +++ b/src/OpenApi/Config/Tags.php @@ -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' @@ -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'; diff --git a/src/Class/Attribute/Request/ConvertRequestBody.php b/src/Unit/Attribute/Parameter/Query/ValueParameter.php similarity index 51% rename from src/Class/Attribute/Request/ConvertRequestBody.php rename to src/Unit/Attribute/Parameter/Query/ValueParameter.php index 799e4800f..8fb356f33 100644 --- a/src/Class/Attribute/Request/ConvertRequestBody.php +++ b/src/Unit/Attribute/Parameter/Query/ValueParameter.php @@ -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 ); } } diff --git a/src/Class/Attribute/Response/ConvertedValueJson.php b/src/Unit/Attribute/Response/ConvertedValueJson.php similarity index 93% rename from src/Class/Attribute/Response/ConvertedValueJson.php rename to src/Unit/Attribute/Response/ConvertedValueJson.php index d4c991d17..c1c025db6 100644 --- a/src/Class/Attribute/Response/ConvertedValueJson.php +++ b/src/Unit/Attribute/Response/ConvertedValueJson.php @@ -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; diff --git a/src/Class/Attribute/Response/QuantityValueUnitsJson.php b/src/Unit/Attribute/Response/QuantityValueUnitsJson.php similarity index 87% rename from src/Class/Attribute/Response/QuantityValueUnitsJson.php rename to src/Unit/Attribute/Response/QuantityValueUnitsJson.php index 9037747ce..3f25f9422 100644 --- a/src/Class/Attribute/Response/QuantityValueUnitsJson.php +++ b/src/Unit/Attribute/Response/QuantityValueUnitsJson.php @@ -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 diff --git a/src/Class/Controller/QuantityValue/ConvertAllController.php b/src/Unit/Controller/QuantityValue/ConvertAllController.php similarity index 60% rename from src/Class/Controller/QuantityValue/ConvertAllController.php rename to src/Unit/Controller/QuantityValue/ConvertAllController.php index ea0e703e4..3bc81f9f9 100644 --- a/src/Class/Controller/QuantityValue/ConvertAllController.php +++ b/src/Unit/Controller/QuantityValue/ConvertAllController.php @@ -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; @@ -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)); } diff --git a/src/Class/Controller/QuantityValue/ConvertController.php b/src/Unit/Controller/QuantityValue/ConvertController.php similarity index 58% rename from src/Class/Controller/QuantityValue/ConvertController.php rename to src/Unit/Controller/QuantityValue/ConvertController.php index b68fd81fc..838e011d8 100644 --- a/src/Class/Controller/QuantityValue/ConvertController.php +++ b/src/Unit/Controller/QuantityValue/ConvertController.php @@ -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; @@ -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)]); } diff --git a/src/Class/Controller/QuantityValue/UnitListController.php b/src/Unit/Controller/QuantityValue/UnitListController.php similarity index 72% rename from src/Class/Controller/QuantityValue/UnitListController.php rename to src/Unit/Controller/QuantityValue/UnitListController.php index b6e26905d..d5b23acbd 100644 --- a/src/Class/Controller/QuantityValue/UnitListController.php +++ b/src/Unit/Controller/QuantityValue/UnitListController.php @@ -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; @@ -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([ diff --git a/src/Class/Event/PreResponse/QuantityValueConversionEvent.php b/src/Unit/Event/PreResponse/QuantityValueConversionEvent.php similarity index 87% rename from src/Class/Event/PreResponse/QuantityValueConversionEvent.php rename to src/Unit/Event/PreResponse/QuantityValueConversionEvent.php index c9c0c15c1..a012ad449 100644 --- a/src/Class/Event/PreResponse/QuantityValueConversionEvent.php +++ b/src/Unit/Event/PreResponse/QuantityValueConversionEvent.php @@ -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 { diff --git a/src/Class/Event/PreResponse/QuantityValueUnitEvent.php b/src/Unit/Event/PreResponse/QuantityValueUnitEvent.php similarity index 87% rename from src/Class/Event/PreResponse/QuantityValueUnitEvent.php rename to src/Unit/Event/PreResponse/QuantityValueUnitEvent.php index 40f58c6bf..5cdac1e9b 100644 --- a/src/Class/Event/PreResponse/QuantityValueUnitEvent.php +++ b/src/Unit/Event/PreResponse/QuantityValueUnitEvent.php @@ -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 { diff --git a/src/Class/Schema/ConvertAllParameters.php b/src/Unit/MappedParameter/ConvertAllUnitsParameter.php similarity index 61% rename from src/Class/Schema/ConvertAllParameters.php rename to src/Unit/MappedParameter/ConvertAllUnitsParameter.php index 16706b2bc..d09b6af2e 100644 --- a/src/Class/Schema/ConvertAllParameters.php +++ b/src/Unit/MappedParameter/ConvertAllUnitsParameter.php @@ -14,22 +14,19 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Class\Schema; +namespace Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter; -use OpenApi\Attributes\Property; -use OpenApi\Attributes\Schema; +use Symfony\Component\Validator\Constraints\NotBlank; -#[Schema( - title: 'Convert All Units Parameters', - required: ['fromUnitId', 'value'], - type: 'object' -)] -final readonly class ConvertAllParameters +/** + * @internal + */ +final readonly class ConvertAllUnitsParameter { public function __construct( - #[Property(description: 'From Unit Id', type: 'string', example: 'm')] + #[NotBlank] private string $fromUnitId, - #[Property(description: 'Value', example: 5, anyOf: [new Schema(type: 'float'), new Schema(type: 'integer')])] + #[NotBlank] private float|int $value, ) { } diff --git a/src/Unit/MappedParameter/ConvertUnitParameter.php b/src/Unit/MappedParameter/ConvertUnitParameter.php new file mode 100644 index 000000000..5e649d5ec --- /dev/null +++ b/src/Unit/MappedParameter/ConvertUnitParameter.php @@ -0,0 +1,50 @@ +fromUnitId; + } + + public function getToUnitId(): string + { + return $this->toUnitId; + } + + public function getValue(): float|int + { + return $this->value; + } +} diff --git a/src/Class/Repository/QuantityValueRepository.php b/src/Unit/Repository/QuantityValueRepository.php similarity index 95% rename from src/Class/Repository/QuantityValueRepository.php rename to src/Unit/Repository/QuantityValueRepository.php index 9d01939d7..578ad30e6 100644 --- a/src/Class/Repository/QuantityValueRepository.php +++ b/src/Unit/Repository/QuantityValueRepository.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Class\Repository; +namespace Pimcore\Bundle\StudioBackendBundle\Unit\Repository; use Pimcore\Model\DataObject\QuantityValue\Unit; use Pimcore\Model\DataObject\QuantityValue\Unit\Listing; diff --git a/src/Class/Repository/QuantityValueRepositoryInterface.php b/src/Unit/Repository/QuantityValueRepositoryInterface.php similarity index 92% rename from src/Class/Repository/QuantityValueRepositoryInterface.php rename to src/Unit/Repository/QuantityValueRepositoryInterface.php index f68f26510..84302c764 100644 --- a/src/Class/Repository/QuantityValueRepositoryInterface.php +++ b/src/Unit/Repository/QuantityValueRepositoryInterface.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Class\Repository; +namespace Pimcore\Bundle\StudioBackendBundle\Unit\Repository; use Pimcore\Model\DataObject\QuantityValue\Unit; diff --git a/src/Class/Schema/ConvertParameters.php b/src/Unit/Schema/ConvertParameters.php similarity index 95% rename from src/Class/Schema/ConvertParameters.php rename to src/Unit/Schema/ConvertParameters.php index d63d0c04c..9bfc51c05 100644 --- a/src/Class/Schema/ConvertParameters.php +++ b/src/Unit/Schema/ConvertParameters.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Class\Schema; +namespace Pimcore\Bundle\StudioBackendBundle\Unit\Schema; use OpenApi\Attributes\Property; use OpenApi\Attributes\Schema; diff --git a/src/Class/Schema/ConvertedQuantityValue.php b/src/Unit/Schema/ConvertedQuantityValue.php similarity index 96% rename from src/Class/Schema/ConvertedQuantityValue.php rename to src/Unit/Schema/ConvertedQuantityValue.php index 900d8fea7..6b3206ad2 100644 --- a/src/Class/Schema/ConvertedQuantityValue.php +++ b/src/Unit/Schema/ConvertedQuantityValue.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Class\Schema; +namespace Pimcore\Bundle\StudioBackendBundle\Unit\Schema; use OpenApi\Attributes\Property; use OpenApi\Attributes\Schema; diff --git a/src/Class/Schema/ConvertedQuantityValues.php b/src/Unit/Schema/ConvertedQuantityValues.php similarity index 96% rename from src/Class/Schema/ConvertedQuantityValues.php rename to src/Unit/Schema/ConvertedQuantityValues.php index 7b70c494c..18e198bfa 100644 --- a/src/Class/Schema/ConvertedQuantityValues.php +++ b/src/Unit/Schema/ConvertedQuantityValues.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Class\Schema; +namespace Pimcore\Bundle\StudioBackendBundle\Unit\Schema; use OpenApi\Attributes\Items; use OpenApi\Attributes\Property; diff --git a/src/Class/Schema/QuantityValueUnit.php b/src/Unit/Schema/QuantityValueUnit.php similarity index 98% rename from src/Class/Schema/QuantityValueUnit.php rename to src/Unit/Schema/QuantityValueUnit.php index 288ebc136..eaf212670 100644 --- a/src/Class/Schema/QuantityValueUnit.php +++ b/src/Unit/Schema/QuantityValueUnit.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Class\Schema; +namespace Pimcore\Bundle\StudioBackendBundle\Unit\Schema; use OpenApi\Attributes\Property; use OpenApi\Attributes\Schema; diff --git a/src/Class/Service/QuantityValueService.php b/src/Unit/Service/QuantityValueService.php similarity index 83% rename from src/Class/Service/QuantityValueService.php rename to src/Unit/Service/QuantityValueService.php index 3c602838a..04927b918 100644 --- a/src/Class/Service/QuantityValueService.php +++ b/src/Unit/Service/QuantityValueService.php @@ -14,20 +14,20 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Class\Service; +namespace Pimcore\Bundle\StudioBackendBundle\Unit\Service; use Exception; use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\QuantityValue\UnitResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\Class\Event\PreResponse\QuantityValueConversionEvent; -use Pimcore\Bundle\StudioBackendBundle\Class\Event\PreResponse\QuantityValueUnitEvent; -use Pimcore\Bundle\StudioBackendBundle\Class\Repository\QuantityValueRepositoryInterface; -use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertAllParameters; -use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertedQuantityValue; -use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertedQuantityValues; -use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertParameters; -use Pimcore\Bundle\StudioBackendBundle\Class\Schema\QuantityValueUnit; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; +use Pimcore\Bundle\StudioBackendBundle\Unit\Event\PreResponse\QuantityValueConversionEvent; +use Pimcore\Bundle\StudioBackendBundle\Unit\Event\PreResponse\QuantityValueUnitEvent; +use Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter\ConvertAllUnitsParameter; +use Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter\ConvertUnitParameter; +use Pimcore\Bundle\StudioBackendBundle\Unit\Repository\QuantityValueRepositoryInterface; +use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\ConvertedQuantityValue; +use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\ConvertedQuantityValues; +use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\QuantityValueUnit; use Pimcore\Model\DataObject\Data\QuantityValue; use Pimcore\Model\DataObject\QuantityValue\Unit; use Pimcore\Model\DataObject\QuantityValue\UnitConversionService; @@ -82,7 +82,7 @@ public function listUnits(): array /** * @throws DatabaseException|NotFoundException */ - public function convertUnit(ConvertParameters $parameters): float|int + public function convertUnit(ConvertUnitParameter $parameters): float|int { return $this->getConvertedValue( $this->getUnit($parameters->getFromUnitId()), @@ -94,7 +94,7 @@ public function convertUnit(ConvertParameters $parameters): float|int /** * @throws DatabaseException|NotFoundException */ - public function convertAllUnits(ConvertAllParameters $parameters): ConvertedQuantityValues + public function convertAllUnits(ConvertAllUnitsParameter $parameters): ConvertedQuantityValues { $fromUnit = $this->getUnit($parameters->getFromUnitId()); $baseUnit = $fromUnit->getBaseunit() ?? $fromUnit; diff --git a/src/Class/Service/QuantityValueServiceInterface.php b/src/Unit/Service/QuantityValueServiceInterface.php similarity index 61% rename from src/Class/Service/QuantityValueServiceInterface.php rename to src/Unit/Service/QuantityValueServiceInterface.php index 553005f85..0824a2ce1 100644 --- a/src/Class/Service/QuantityValueServiceInterface.php +++ b/src/Unit/Service/QuantityValueServiceInterface.php @@ -14,14 +14,14 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Class\Service; +namespace Pimcore\Bundle\StudioBackendBundle\Unit\Service; -use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertAllParameters; -use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertedQuantityValues; -use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertParameters; -use Pimcore\Bundle\StudioBackendBundle\Class\Schema\QuantityValueUnit; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; +use Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter\ConvertAllUnitsParameter; +use Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter\ConvertUnitParameter; +use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\ConvertedQuantityValues; +use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\QuantityValueUnit; /** * @internal @@ -36,10 +36,10 @@ public function listUnits(): array; /** * @throws DatabaseException|NotFoundException */ - public function convertUnit(ConvertParameters $parameters): float|int; + public function convertUnit(ConvertUnitParameter $parameters): float|int; /** * @throws DatabaseException|NotFoundException */ - public function convertAllUnits(ConvertAllParameters $parameters): ConvertedQuantityValues; + public function convertAllUnits(ConvertAllUnitsParameter $parameters): ConvertedQuantityValues; } diff --git a/translations/studio_api_docs.en.yaml b/translations/studio_api_docs.en.yaml index c100ad6af..526f20efd 100644 --- a/translations/studio_api_docs.en.yaml +++ b/translations/studio_api_docs.en.yaml @@ -487,6 +487,7 @@ tag_update_by_id_description: | See the full description of updatable fields with the schema Change Tag Parameters tag_update_by_id_success_response: Successfully updated tag data as JSON tag_update_by_id_summary: Update a tag by ID +tag_units_description: Units operations like convert and get all units tag_user_description: User Management operations tag_versions_description: Versions operations to get/list/publish/delete and cleanup versions @@ -623,16 +624,16 @@ class_object_brick_object_layout_description: | Get all layouts from the object bricks for an given object class_object_brick_object_layout_summary: Get all layouts from the object bricks for an given object class_object_brick_object_layout_success_response: List of layouts -class_quantity_value_unit_list_description: | +unit_quantity_value_list_description: | List of available quantity value units -class_quantity_value_unit_list_summary: List of available quantity value units -class_quantity_value_unit_list_success_response: List of quantity value units -class_quantity_value_unit_convert_description: | +unit_quantity_value_list_summary: List of available quantity value units +unit_quantity_value_list_success_response: List of quantity value units +unit_quantity_value_convert_description: | Convert quantity {value} from one unit to another based on the given {fromUnitId} and {toUnitId} -class_quantity_value_unit_convert_summary: Convert quantity value from one unit to another -class_quantity_value_unit_convert_success_response: Converted quantity value -class_quantity_value_unit_convert_all_description: | +unit_quantity_value_convert_summary: Convert quantity value from one unit to another +unit_quantity_value_convert_success_response: Converted quantity value +unit_quantity_value_convert_all_description: | Convert quantity {value} from one unit to all other available units based on the given {fromUnitId}.
Units have to have {fromUnitId} defined as base unit to be considered for conversion. -class_quantity_value_unit_convert_all_summary: Convert quantity value from one unit to all other related units -class_quantity_value_unit_convert_all_success_response: Converted quantity value \ No newline at end of file +unit_quantity_value_convert_all_summary: Convert quantity value from one unit to all other related units +unit_quantity_value_convert_all_success_response: Converted quantity value \ No newline at end of file