mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-06 05:19:43 +00:00
[WIP] Add aggregated address search API endpoint
Introduced a new API endpoint `/api/1.0/main/address-reference/aggregated/search` for aggregated address reference search with support for query filtering. Extended repository with `findAggregatedBySearchString` method and updated materialized view `view_chill_main_address_reference`. Added test coverage and API specification details.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Repository\AddressReferenceRepository;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
final readonly class AddressReferenceAggregatedApiController
|
||||
{
|
||||
public function __construct(
|
||||
private Security $security,
|
||||
private AddressReferenceRepository $addressReferenceRepository,
|
||||
) {}
|
||||
|
||||
#[Route(path: '/api/1.0/main/address-reference/aggregated/search')]
|
||||
public function search(Request $request): JsonResponse
|
||||
{
|
||||
if (!$this->security->isGranted('IS_AUTHENTICATED')) {
|
||||
throw new AccessDeniedHttpException();
|
||||
}
|
||||
|
||||
if (!$request->query->has('q')) {
|
||||
throw new BadRequestHttpException('Parameter "q" is required.');
|
||||
}
|
||||
|
||||
$q = trim($request->query->get('q'));
|
||||
|
||||
if ('' === $q) {
|
||||
throw new BadRequestHttpException('Parameter "q" is required and cannot be empty.');
|
||||
}
|
||||
|
||||
$result = $this->addressReferenceRepository->findAggregatedBySearchString($q);
|
||||
|
||||
return new JsonResponse(iterator_to_array($result));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user