|
| 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\Class\Controller; |
| 15 | + |
| 16 | +use OpenApi\Attributes\Get; |
| 17 | +use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\FieldsByTypeParameters; |
| 18 | +use Pimcore\Bundle\StudioBackendBundle\Class\Schema\FieldByType; |
| 19 | +use Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldsByTypeServiceInterface; |
| 20 | +use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; |
| 21 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\StringParameter; |
| 22 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection; |
| 23 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson; |
| 24 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; |
| 25 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; |
| 26 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; |
| 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\MapQueryString; |
| 32 | +use Symfony\Component\Routing\Attribute\Route; |
| 33 | +use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 34 | +use Symfony\Component\Serializer\SerializerInterface; |
| 35 | +use function count; |
| 36 | + |
| 37 | +/** |
| 38 | + * @internal |
| 39 | + */ |
| 40 | +final class FieldsByTypeController extends AbstractApiController |
| 41 | +{ |
| 42 | + use PaginatedResponseTrait; |
| 43 | + |
| 44 | + private const string ROUTE = '/class/definition/fields-by-type'; |
| 45 | + |
| 46 | + public function __construct( |
| 47 | + SerializerInterface $serializer, |
| 48 | + private readonly FieldsByTypeServiceInterface $fieldsByTypeService, |
| 49 | + ) { |
| 50 | + parent::__construct($serializer); |
| 51 | + } |
| 52 | + |
| 53 | + #[Route( |
| 54 | + self::ROUTE, |
| 55 | + name: 'pimcore_studio_api_class_fields_by_type', |
| 56 | + methods: ['GET'] |
| 57 | + )] |
| 58 | + #[IsGranted(UserPermissions::CLASS_DEFINITION->value)] |
| 59 | + #[Get( |
| 60 | + path: self::PREFIX . self::ROUTE, |
| 61 | + operationId: 'class_get_fields_by_type', |
| 62 | + description: 'class_get_fields_by_type_description', |
| 63 | + summary: 'class_get_fields_by_type_summary', |
| 64 | + tags: [Tags::ClassDefinition->value], |
| 65 | + )] |
| 66 | + #[StringParameter( |
| 67 | + name: 'classId', |
| 68 | + example: 'EV', |
| 69 | + description: 'The class ID to retrieve fields for.', |
| 70 | + required: true |
| 71 | + )] |
| 72 | + #[StringParameter( |
| 73 | + name: 'type', |
| 74 | + example: 'manyToOneRelation,objectbricks', |
| 75 | + description: 'Comma-separated list of field types to filter by.', |
| 76 | + required: true |
| 77 | + )] |
| 78 | + #[SuccessResponse( |
| 79 | + description: 'class_get_fields_by_type_success_response', |
| 80 | + content: new CollectionJson(new GenericCollection(FieldByType::class)) |
| 81 | + )] |
| 82 | + #[DefaultResponses([ |
| 83 | + HttpResponseCodes::UNAUTHORIZED, |
| 84 | + HttpResponseCodes::NOT_FOUND, |
| 85 | + ])] |
| 86 | + public function getFieldsByType( |
| 87 | + #[MapQueryString] FieldsByTypeParameters $parameters |
| 88 | + ): JsonResponse { |
| 89 | + $fields = $this->fieldsByTypeService->getFieldsByType($parameters); |
| 90 | + |
| 91 | + return $this->getPaginatedCollection($this->serializer, $fields, count($fields)); |
| 92 | + } |
| 93 | +} |
0 commit comments