-
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.
feat: add endpoints related to quantity value
- Loading branch information
Showing
19 changed files
with
1,091 additions
and
1 deletion.
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
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\Class\Attribute\Request; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\RequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ConvertParameters; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class ConvertRequestBody extends RequestBody | ||
{ | ||
public function __construct(string $ref = ConvertParameters::class) | ||
{ | ||
parent::__construct( | ||
required: true, | ||
content: new JsonContent(ref: $ref) | ||
); | ||
} | ||
} |
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,44 @@ | ||
<?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\Class\Attribute\Response; | ||
|
||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\Property; | ||
use OpenApi\Attributes\Schema; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ConvertedValueJson extends JsonContent | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: ['data'], | ||
properties: [ | ||
new Property( | ||
'data', | ||
title: 'data', | ||
description: 'Converted value', | ||
example: 2.0, | ||
anyOf: [new Schema(type: 'float'), new Schema(type: 'integer')], | ||
), | ||
], | ||
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,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\Class\Attribute\Response; | ||
|
||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\Property; | ||
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\QuantityValueUnit; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class QuantityValueUnitsJson extends JsonContent | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: ['items'], | ||
properties: [ | ||
new Property( | ||
'items', | ||
type: 'array', | ||
items: new Items(ref: QuantityValueUnit::class) | ||
), | ||
], | ||
type: 'object', | ||
); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/Class/Controller/QuantityValue/ConvertAllController.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,88 @@ | ||
<?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\Class\Controller\QuantityValue; | ||
|
||
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\Schema\ConvertParameters; | ||
use Pimcore\Bundle\StudioBackendBundle\Class\Service\QuantityValueServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\DataJson; | ||
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 Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ConvertAllController extends AbstractApiController | ||
{ | ||
use ElementProviderTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly QuantityValueServiceInterface $quantityValueService | ||
|
||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws AccessDeniedException|DatabaseException|NotFoundException|UserNotFoundException | ||
*/ | ||
#[Route( | ||
'/class/quantity-value/convert-all', | ||
name: 'pimcore_studio_api_get_class_quantity_value_convert_all', | ||
methods: ['POST'] | ||
)] | ||
#[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] | ||
)] | ||
#[SuccessResponse( | ||
description: 'class_quantity_value_unit_convert_all_success_response', | ||
content: new JsonContent(ref: ConvertedQuantityValues::class) | ||
)] | ||
#[ConvertRequestBody(ConvertAllParameters::class)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND | ||
])] | ||
public function get(#[MapRequestPayload] ConvertAllParameters $parameters): JsonResponse | ||
{ | ||
return $this->jsonResponse($this->quantityValueService->convertAllUnits($parameters)); | ||
} | ||
} |
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,83 @@ | ||
<?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\Class\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 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\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 Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ConvertController extends AbstractApiController | ||
{ | ||
use ElementProviderTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly QuantityValueServiceInterface $quantityValueService | ||
|
||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws DatabaseException|NotFoundException | ||
*/ | ||
#[Route( | ||
'/class/quantity-value/convert', | ||
name: 'pimcore_studio_api_get_class_quantity_value_convert', | ||
methods: ['POST'] | ||
)] | ||
#[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] | ||
)] | ||
#[SuccessResponse( | ||
description: 'class_quantity_value_unit_convert_success_response', | ||
content: new ConvertedValueJson() | ||
)] | ||
#[ConvertRequestBody] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND | ||
])] | ||
public function get(#[MapRequestPayload] ConvertParameters $parameters): JsonResponse | ||
{ | ||
return $this->jsonResponse(['data' => $this->quantityValueService->convertUnit($parameters)]); | ||
} | ||
} |
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,75 @@ | ||
<?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\Class\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\Exception\Api\AccessDeniedException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; | ||
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 Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class UnitListController extends AbstractApiController | ||
{ | ||
use ElementProviderTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly QuantityValueServiceInterface $quantityValueService | ||
|
||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
#[Route( | ||
'/class/quantity-value/unit-list', | ||
name: 'pimcore_studio_api_get_class_quantity_value_unit_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] | ||
)] | ||
#[SuccessResponse( | ||
description: 'class_quantity_value_unit_list_success_response', | ||
content: new QuantityValueUnitsJson() | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED | ||
])] | ||
public function listUnits(): JsonResponse | ||
{ | ||
return $this->jsonResponse(['items' => $this->quantityValueService->listUnits()]); | ||
} | ||
} |
Oops, something went wrong.