Merge branch 'Marvin'
This commit is contained in:
@@ -2,7 +2,13 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Lieu;
|
||||
use App\Entity\Ville;
|
||||
use App\Repository\VilleRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
@@ -15,4 +21,93 @@ class LieuController extends AbstractController
|
||||
'controller_name' => 'LieuController',
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/lieu/set', name: 'lieu_set', methods: ['POST'])]
|
||||
public function setLieu(
|
||||
Request $request,
|
||||
VilleRepository $villeRepository,
|
||||
EntityManagerInterface $entityManager
|
||||
): JsonResponse {
|
||||
$data = json_decode($request->getContent(), true);
|
||||
|
||||
|
||||
if (!isset($data['nom'], $data['rue'], $data['latitude'], $data['longitude'], $data['villeId'])) {
|
||||
return new JsonResponse(['error' => 'Données manquantes'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
$ville = $villeRepository->find($data['villeId']);
|
||||
if (!$ville) {
|
||||
return new JsonResponse(['error' => 'Ville non trouvée'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
$lieu = new Lieu();
|
||||
$lieu->setNom($data['nom']);
|
||||
$lieu->setRue($data['rue']);
|
||||
$lieu->setLatitude($data['latitude']);
|
||||
$lieu->setLongitude($data['longitude']);
|
||||
$lieu->setVille($ville);
|
||||
|
||||
|
||||
$entityManager->persist($lieu);
|
||||
$entityManager->flush();
|
||||
|
||||
|
||||
return new JsonResponse([
|
||||
'id' => $lieu->getIdLieu(),
|
||||
'nom' => $lieu->getNom(),
|
||||
'rue' => $lieu->getRue(),
|
||||
'latitude' => $lieu->getLatitude(),
|
||||
'longitude' => $lieu->getLongitude(),
|
||||
], Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
#[Route('/get-bounds/{villeId}', name: 'get_bounds', methods: ['GET'])]
|
||||
public function getBounds(VilleRepository $villeRepository, string $villeId): JsonResponse
|
||||
{
|
||||
$ville = $villeRepository->find($villeId);
|
||||
|
||||
if (!$ville) {
|
||||
return new JsonResponse(['error' => 'Ville non trouvée'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Utilisez l'API Nominatim pour récupérer les bounds
|
||||
$params = [
|
||||
'q' => $ville->getNom(),
|
||||
'format' => 'json',
|
||||
'polygon_geojson' => 1,
|
||||
];
|
||||
$url = 'https://nominatim.openstreetmap.org/search?' . http_build_query($params);
|
||||
|
||||
try {
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'header' => "User-Agent: MyApp/1.0 (contact@myapp.com)\r\n",
|
||||
],
|
||||
]);
|
||||
|
||||
$response = file_get_contents($url, false, $context);
|
||||
$data = json_decode($response, true);
|
||||
|
||||
if (!empty($data[0]['boundingbox'])) {
|
||||
$boundingBox = $data[0]['boundingbox'];
|
||||
$centerLat = ($boundingBox[0] + $boundingBox[1]) / 2;
|
||||
$centerLng = ($boundingBox[2] + $boundingBox[3]) / 2;
|
||||
|
||||
return new JsonResponse([
|
||||
'south' => $boundingBox[0],
|
||||
'north' => $boundingBox[1],
|
||||
'west' => $boundingBox[2],
|
||||
'east' => $boundingBox[3],
|
||||
'centerLat' => $centerLat,
|
||||
'centerLng' => $centerLng,
|
||||
]);
|
||||
}
|
||||
|
||||
return new JsonResponse(['error' => 'Bounding box non trouvée'], Response::HTTP_NOT_FOUND);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse(['error' => $e->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class Etat
|
||||
$this->sorties = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getIdEtat(): ?string // Changement ici
|
||||
public function getIdEtat(): ?string
|
||||
{
|
||||
return $this->idEtat;
|
||||
}
|
||||
@@ -68,7 +68,6 @@ class Etat
|
||||
public function removeSortie(Sortie $sortie): self
|
||||
{
|
||||
if ($this->sorties->removeElement($sortie)) {
|
||||
// Set the owning side to null (unless already changed)
|
||||
if ($sortie->getEtat() === $this) {
|
||||
$sortie->setEtat(null);
|
||||
}
|
||||
|
||||
@@ -137,4 +137,6 @@ class Lieu
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class SortieType extends AbstractType
|
||||
'choice_label' => 'nom',
|
||||
'label' => 'Lieu',
|
||||
'placeholder' => 'Sélectionnez une ville d\'abord',
|
||||
'choices' => [], // Pas de choix au début
|
||||
'choices' => [],
|
||||
'attr' => ['id' => 'lieu-select'],
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user