Skip to content

Commit 4f94297

Browse files
authored
[Quantity Value]: Add definition endpoints (#1678)
* add quantity value endpoints * Apply php-cs-fixer changes * fix: code style
1 parent 1347f4a commit 4f94297

26 files changed

Lines changed: 1204 additions & 121 deletions

config/units.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@ services:
1818
Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueServiceInterface:
1919
class: Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueService
2020

21+
Pimcore\Bundle\StudioBackendBundle\Unit\Service\ConversionServiceInterface:
22+
class: Pimcore\Bundle\StudioBackendBundle\Unit\Service\ConversionService
23+
24+
#
25+
# Hydrators
26+
#
27+
28+
Pimcore\Bundle\StudioBackendBundle\Unit\Hydrator\QuantityValueHydratorInterface:
29+
class: Pimcore\Bundle\StudioBackendBundle\Unit\Hydrator\QuantityValueHydrator
30+
2131
#
2232
# Repositories
2333
#
2434

2535
Pimcore\Bundle\StudioBackendBundle\Unit\Repository\QuantityValueRepositoryInterface:
26-
class: Pimcore\Bundle\StudioBackendBundle\Unit\Repository\QuantityValueRepository
36+
class: Pimcore\Bundle\StudioBackendBundle\Unit\Repository\QuantityValueRepository

src/Class/Service/ClassDefinitionTreeService.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Pimcore\Bundle\StudioBackendBundle\Class\Service;
1515

16-
use Pimcore\Bundle\StudioBackendBundle\Class\Event\ClassDefinitionEvent;
1716
use Pimcore\Bundle\StudioBackendBundle\Class\Event\ClassDefinitionFolderListEvent;
1817
use Pimcore\Bundle\StudioBackendBundle\Class\Event\ClassDefinitionTreeEvent;
1918
use Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\Folder\ClassDefinitionFolderItemHydratorInterface;
@@ -82,7 +81,7 @@ public function getClassDefinitionIdsInsideFolder(int $folderId): array
8281
$class = $this->classDefinitionFolderListHydrator->hydrate($classDefinition);
8382
$this->eventDispatcher->dispatch(
8483
new ClassDefinitionFolderListEvent($class),
85-
ClassDefinitionEvent::EVENT_NAME
84+
ClassDefinitionFolderListEvent::EVENT_NAME
8685
);
8786
$hydratedClassDefinitions[] = $class;
8887
}

src/Class/Service/FieldCollection/LayoutDefinitionService.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
use Pimcore\Model\DataObject\ClassDefinitionInterface;
3333
use Pimcore\Model\DataObject\Concrete;
3434
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
35-
use function get_class;
3635
use function sprintf;
3736

3837
/**
@@ -63,7 +62,7 @@ public function getLayoutDefinitionsForObject(int $dataObjectId): array
6362

6463
if (!$dataObject instanceof Concrete) {
6564
throw new InvalidElementTypeException(
66-
sprintf('DataObject class (%s) is not a concrete object', get_class($dataObject))
65+
sprintf('DataObject id (%s) is not a concrete object', $dataObjectId)
6766
);
6867
}
6968

src/DataObject/Service/LayoutService.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use Pimcore\Model\Element\ElementInterface;
3636
use Pimcore\Model\UserInterface;
3737
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
38-
use function get_class;
3938
use function in_array;
4039
use function sprintf;
4140

@@ -76,7 +75,7 @@ public function getDataObjectLayout(int $id, ?string $layoutId = null): Layout
7675

7776
if (!$dataObject instanceof Concrete) {
7877
throw new InvalidElementTypeException(
79-
sprintf('DataObject class (%s) is not a concrete object', get_class($dataObject))
78+
sprintf('DataObject id (%s) is not a concrete object', $dataObject->getId())
8079
);
8180
}
8281

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Controller\QuantityValue;
15+
16+
use OpenApi\Attributes\Post;
17+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
18+
use Pimcore\Bundle\StudioBackendBundle\Filter\Attribute\Request\CollectionRequestBody;
19+
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionFilterParameter;
20+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection;
21+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
22+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
23+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
24+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
25+
use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\QuantityValueUnit;
26+
use Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueServiceInterface;
27+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
28+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
29+
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
30+
use Symfony\Component\HttpFoundation\JsonResponse;
31+
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
32+
use Symfony\Component\Routing\Attribute\Route;
33+
use Symfony\Component\Security\Http\Attribute\IsGranted;
34+
use Symfony\Component\Serializer\SerializerInterface;
35+
36+
/**
37+
* @internal
38+
*/
39+
final class CollectionController extends AbstractApiController
40+
{
41+
use PaginatedResponseTrait;
42+
43+
private const string ROUTE = '/unit/quantity-value/units/collection';
44+
45+
public function __construct(
46+
SerializerInterface $serializer,
47+
private readonly QuantityValueServiceInterface $quantityValueService,
48+
) {
49+
parent::__construct($serializer);
50+
}
51+
52+
#[Route(
53+
self::ROUTE,
54+
name: 'pimcore_studio_api_unit_quantity_value_units_collection',
55+
methods: ['POST'],
56+
priority: 10
57+
)]
58+
#[IsGranted(UserPermissions::QUANTITY_VALUE_UNITS->value)]
59+
#[Post(
60+
path: self::PREFIX . self::ROUTE,
61+
operationId: 'unit_quantity_value_units_collection',
62+
description: 'unit_quantity_value_units_collection_description',
63+
summary: 'unit_quantity_value_units_collection_summary',
64+
tags: [Tags::Units->value]
65+
)]
66+
#[CollectionRequestBody]
67+
#[SuccessResponse(
68+
description: 'unit_quantity_value_units_collection_success_response',
69+
content: new CollectionJson(new GenericCollection(QuantityValueUnit::class))
70+
)]
71+
#[DefaultResponses([
72+
HttpResponseCodes::UNAUTHORIZED,
73+
])]
74+
public function getUnitCollection(
75+
#[MapRequestPayload] CollectionFilterParameter $parameters
76+
): JsonResponse {
77+
$collection = $this->quantityValueService->listUnitCollection($parameters);
78+
79+
return $this->getPaginatedCollection(
80+
$this->serializer,
81+
$collection->getItems(),
82+
$collection->getTotalItems()
83+
);
84+
}
85+
}

src/Unit/Controller/QuantityValue/ConvertAllController.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@
1616
use OpenApi\Attributes\Get;
1717
use OpenApi\Attributes\JsonContent;
1818
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
19-
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
20-
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
2119
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\TextFieldParameter;
2220
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
2321
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
2422
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
2523
use Pimcore\Bundle\StudioBackendBundle\Unit\Attribute\Parameter\Query\ValueParameter;
2624
use Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter\ConvertAllUnitsParameter;
2725
use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\ConvertedQuantityValues;
28-
use Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueServiceInterface;
26+
use Pimcore\Bundle\StudioBackendBundle\Unit\Service\ConversionServiceInterface;
2927
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
3028
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
31-
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait;
3229
use Symfony\Component\HttpFoundation\JsonResponse;
3330
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
3431
use Symfony\Component\Routing\Attribute\Route;
@@ -40,19 +37,13 @@
4037
*/
4138
final class ConvertAllController extends AbstractApiController
4239
{
43-
use ElementProviderTrait;
44-
4540
public function __construct(
4641
SerializerInterface $serializer,
47-
private readonly QuantityValueServiceInterface $quantityValueService
48-
42+
private readonly ConversionServiceInterface $conversionService,
4943
) {
5044
parent::__construct($serializer);
5145
}
5246

53-
/**
54-
* @throws DatabaseException|NotFoundException
55-
*/
5647
#[Route(
5748
'/unit/quantity-value/convert-all',
5849
name: 'pimcore_studio_api_unit_quantity_value_convert_all',
@@ -81,8 +72,8 @@ public function __construct(
8172
HttpResponseCodes::NOT_FOUND,
8273
HttpResponseCodes::INTERNAL_SERVER_ERROR,
8374
])]
84-
public function covertAll(#[MapQueryString] ConvertAllUnitsParameter $parameters): JsonResponse
75+
public function convertAll(#[MapQueryString] ConvertAllUnitsParameter $parameters): JsonResponse
8576
{
86-
return $this->jsonResponse($this->quantityValueService->convertAllUnits($parameters));
77+
return $this->jsonResponse($this->conversionService->convertAllUnits($parameters));
8778
}
8879
}

src/Unit/Controller/QuantityValue/ConvertController.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,16 @@
1515

1616
use OpenApi\Attributes\Get;
1717
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
18-
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
19-
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
2018
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\TextFieldParameter;
2119
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
2220
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
2321
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
2422
use Pimcore\Bundle\StudioBackendBundle\Unit\Attribute\Parameter\Query\ValueParameter;
2523
use Pimcore\Bundle\StudioBackendBundle\Unit\Attribute\Response\ConvertedValueJson;
2624
use Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter\ConvertUnitParameter;
27-
use Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueServiceInterface;
25+
use Pimcore\Bundle\StudioBackendBundle\Unit\Service\ConversionServiceInterface;
2826
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
2927
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
30-
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait;
3128
use Symfony\Component\HttpFoundation\JsonResponse;
3229
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
3330
use Symfony\Component\Routing\Attribute\Route;
@@ -39,19 +36,13 @@
3936
*/
4037
final class ConvertController extends AbstractApiController
4138
{
42-
use ElementProviderTrait;
43-
4439
public function __construct(
4540
SerializerInterface $serializer,
46-
private readonly QuantityValueServiceInterface $quantityValueService
47-
41+
private readonly ConversionServiceInterface $conversionService,
4842
) {
4943
parent::__construct($serializer);
5044
}
5145

52-
/**
53-
* @throws DatabaseException|NotFoundException
54-
*/
5546
#[Route(
5647
'/unit/quantity-value/convert',
5748
name: 'pimcore_studio_api_unit_quantity_value_convert',
@@ -87,6 +78,6 @@ public function __construct(
8778
])]
8879
public function convert(#[MapQueryString] ConvertUnitParameter $parameters): JsonResponse
8980
{
90-
return $this->jsonResponse(['data' => $this->quantityValueService->convertUnit($parameters)]);
81+
return $this->jsonResponse(['data' => $this->conversionService->convertUnit($parameters)]);
9182
}
9283
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Unit\Controller\QuantityValue;
15+
16+
use OpenApi\Attributes\JsonContent;
17+
use OpenApi\Attributes\Post;
18+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
19+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Request\ReferenceRequestBody;
20+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
21+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
22+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
23+
use Pimcore\Bundle\StudioBackendBundle\Unit\MappedParameter\CreateUnitParameters;
24+
use Pimcore\Bundle\StudioBackendBundle\Unit\Schema\QuantityValueUnit;
25+
use Pimcore\Bundle\StudioBackendBundle\Unit\Service\QuantityValueServiceInterface;
26+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
27+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
28+
use Symfony\Component\HttpFoundation\JsonResponse;
29+
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
30+
use Symfony\Component\Routing\Attribute\Route;
31+
use Symfony\Component\Security\Http\Attribute\IsGranted;
32+
use Symfony\Component\Serializer\SerializerInterface;
33+
34+
/**
35+
* @internal
36+
*/
37+
final class CreateController extends AbstractApiController
38+
{
39+
private const string ROUTE = '/unit/quantity-value/units';
40+
41+
public function __construct(
42+
SerializerInterface $serializer,
43+
private readonly QuantityValueServiceInterface $quantityValueService,
44+
) {
45+
parent::__construct($serializer);
46+
}
47+
48+
#[Route(self::ROUTE, name: 'pimcore_studio_api_unit_quantity_value_units_create', methods: ['POST'])]
49+
#[IsGranted(UserPermissions::QUANTITY_VALUE_UNITS->value)]
50+
#[Post(
51+
path: self::PREFIX . self::ROUTE,
52+
operationId: 'unit_quantity_value_units_create',
53+
description: 'unit_quantity_value_units_create_description',
54+
summary: 'unit_quantity_value_units_create_summary',
55+
tags: [Tags::Units->value]
56+
)]
57+
#[ReferenceRequestBody(CreateUnitParameters::class)]
58+
#[SuccessResponse(
59+
description: 'unit_quantity_value_units_create_success_response',
60+
content: new JsonContent(ref: QuantityValueUnit::class, type: 'object')
61+
)]
62+
#[DefaultResponses([
63+
HttpResponseCodes::UNAUTHORIZED,
64+
HttpResponseCodes::BAD_REQUEST,
65+
])]
66+
public function createUnit(#[MapRequestPayload] CreateUnitParameters $parameters): JsonResponse
67+
{
68+
return $this->jsonResponse($this->quantityValueService->createUnit($parameters));
69+
}
70+
}

0 commit comments

Comments
 (0)