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:
@@ -67,6 +67,40 @@ final readonly class AddressReferenceRepository implements ObjectRepository
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
public function findAggregatedBySearchString(string $search, PostalCode|int|null $postalCode = null, int $firstResult = 0, int $maxResults = 50): iterable
|
||||
{
|
||||
$terms = $this->buildTermsFromSearchString($search);
|
||||
if ([] === $terms) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$connection = $this->entityManager->getConnection();
|
||||
$qb = $connection->createQueryBuilder();
|
||||
|
||||
$qb->select('var.street AS street', 'cmpc.id AS postcode_id', 'cmpc.code AS code', 'cmpc.label AS label', 'jsonb_object_agg(var.address_id, var.streetnumber ORDER BY var.row_number) AS positions')
|
||||
->from('view_chill_main_address_reference', 'var')
|
||||
->innerJoin('var', 'chill_main_postal_code', 'cmpc', 'cmpc.id = var.postcode_id')
|
||||
->groupBy('cmpc.id', 'var.street')
|
||||
->setFirstResult($firstResult)
|
||||
->setMaxResults($maxResults);
|
||||
|
||||
$paramId = 0;
|
||||
|
||||
foreach ($terms as $k => $term) {
|
||||
$qb->andWhere('var.address like ?');
|
||||
$qb->setParameter(++$paramId, "%{$term}%");
|
||||
}
|
||||
|
||||
if (null !== $postalCode) {
|
||||
$qb->andWhere('var.postcode_id = ?');
|
||||
$qb->setParameter(++$paramId, $postalCode instanceof PostalCode ? $postalCode->getId() : $postalCode);
|
||||
}
|
||||
|
||||
$result = $qb->executeQuery();
|
||||
|
||||
return $result->iterateAssociative();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<AddressReference>
|
||||
*/
|
||||
|
Reference in New Issue
Block a user