Skip to content

Commit

Permalink
feat: add endpoints related to quantity value
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmzig committed Nov 27, 2024
1 parent 758fe40 commit 9d901bb
Show file tree
Hide file tree
Showing 19 changed files with 1,091 additions and 1 deletion.
5 changes: 5 additions & 0 deletions config/class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ services:
Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\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
34 changes: 34 additions & 0 deletions src/Class/Attribute/Request/ConvertRequestBody.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\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)
);
}
}
44 changes: 44 additions & 0 deletions src/Class/Attribute/Response/ConvertedValueJson.php
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',
);
}
}
43 changes: 43 additions & 0 deletions src/Class/Attribute/Response/QuantityValueUnitsJson.php
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 src/Class/Controller/QuantityValue/ConvertAllController.php
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));
}
}
83 changes: 83 additions & 0 deletions src/Class/Controller/QuantityValue/ConvertController.php
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)]);
}
}
75 changes: 75 additions & 0 deletions src/Class/Controller/QuantityValue/UnitListController.php
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()]);
}
}
Loading

0 comments on commit 9d901bb

Please sign in to comment.