diff --git a/src/Bundle/ChillMainBundle/Controller/PostalCodeForAddressReferenceApiController.php b/src/Bundle/ChillMainBundle/Controller/PostalCodeForAddressReferenceApiController.php new file mode 100644 index 000000000..873e0c890 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/PostalCodeForAddressReferenceApiController.php @@ -0,0 +1,47 @@ +security->isGranted('IS_AUTHENTICATED')) { + throw new AccessDeniedHttpException(); + } + + $search = $request->query->get('q'); + + if (null === $search || '' === trim($search)) { + throw new BadRequestHttpException('No search query provided'); + } + + $postalCodes = iterator_to_array($this->postalCodeForAddressReferenceRepository->findPostalCode($search)); + + return new JsonResponse($postalCodes, json: false); + } +} diff --git a/src/Bundle/ChillMainBundle/Repository/PostalCodeForAddressReferenceRepository.php b/src/Bundle/ChillMainBundle/Repository/PostalCodeForAddressReferenceRepository.php index e78fd1115..7dc0837dc 100644 --- a/src/Bundle/ChillMainBundle/Repository/PostalCodeForAddressReferenceRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/PostalCodeForAddressReferenceRepository.php @@ -51,7 +51,9 @@ final readonly class PostalCodeForAddressReferenceRepository implements PostalCo $result = $qb->executeQuery(); - return $result->iterateAssociative(); + foreach ($result->iterateAssociative() as $row) { + yield [...$row, 'country_name' => json_decode($row['country_name'], true, 512, JSON_THROW_ON_ERROR)]; + } } private function buildTermsFromSearchString(string $search): array diff --git a/src/Bundle/ChillMainBundle/chill.api.specs.yaml b/src/Bundle/ChillMainBundle/chill.api.specs.yaml index 9c5f7d84a..efb1431d3 100644 --- a/src/Bundle/ChillMainBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillMainBundle/chill.api.specs.yaml @@ -614,6 +614,25 @@ paths: description: "Unauthorized" 400: description: "Bad Request" + /1.0/main/address-reference/postal-code/search: + get: + tags: + - address + summary: Search for postal code that can contains the search query + parameters: + - name: q + in: query + required: true + description: The search pattern + schema: + type: string + responses: + 200: + description: "ok" + 401: + description: "Unauthorized" + 400: + description: "Bad Request" /1.0/main/postal-code/search.json: get: tags: