46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\Ville;
|
|
use App\Repository\LieuRepository;
|
|
use App\Repository\VilleRepository;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
class VilleController extends AbstractController
|
|
{
|
|
|
|
#[Route('/get-lieux/{id}', name: 'get_lieux', methods: ['GET'])]
|
|
public function getLieux(string $id, VilleRepository $villeRepository, LieuRepository $lieuRepository): JsonResponse
|
|
{
|
|
$ville = $villeRepository->find($id);
|
|
|
|
if (!$ville) {
|
|
return new JsonResponse(['error' => 'Ville non trouvée'], Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
$lieux = $lieuRepository->findBy(['ville' => $ville]);
|
|
$response = [];
|
|
|
|
foreach ($lieux as $lieu) {
|
|
$response[] = [
|
|
'id' => $lieu->getIdLieu(),
|
|
'nom' => $lieu->getNom(),
|
|
'rue' => $lieu->getRue(),
|
|
'codePostal' => $lieu->getVille()->getCodePostal(),
|
|
'latitude' => $lieu->getLatitude(),
|
|
'longitude' => $lieu->getLongitude(),
|
|
];
|
|
}
|
|
|
|
return new JsonResponse($response);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|