feat(custom-fields) : ajoute endpoint GET /api/custom-fields/names
Retourne la liste plate des noms de champs perso distincts (table custom_fields), pour alimenter une autocompletion cote frontend. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
37
src/Controller/CustomFieldNamesController.php
Normal file
37
src/Controller/CustomFieldNamesController.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
#[AsController]
|
||||||
|
final class CustomFieldNamesController
|
||||||
|
{
|
||||||
|
public function __construct(private readonly Connection $connection) {}
|
||||||
|
|
||||||
|
#[Route(
|
||||||
|
path: '/api/custom-fields/names',
|
||||||
|
name: 'api_custom_fields_names',
|
||||||
|
methods: ['GET']
|
||||||
|
)]
|
||||||
|
#[IsGranted('ROLE_VIEWER')]
|
||||||
|
public function __invoke(): JsonResponse
|
||||||
|
{
|
||||||
|
$sql = <<<'SQL'
|
||||||
|
SELECT DISTINCT name
|
||||||
|
FROM custom_fields
|
||||||
|
WHERE name IS NOT NULL AND name <> ''
|
||||||
|
ORDER BY name ASC
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
$names = $this->connection->fetchFirstColumn($sql);
|
||||||
|
|
||||||
|
return new JsonResponse($names);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user