caprigis-api/src/Controller/SphericalPhotoController.php
2024-11-24 21:43:52 +01:00

50 lines
1.4 KiB
PHP

<?php
namespace App\Controller;
use App\Entity\SphericalPhoto;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
class SphericalPhotoController extends AbstractController
{
#[Route('/spherical', name: 'app_spherical')]
public function index(
EntityManagerInterface $em
): JsonResponse
{
$repo = $em->getRepository(SphericalPhoto::class);
$photos = $repo->findAll();
foreach ($photos as $key => $photo) {
$coords = $repo->coordinates($photo->getId());
$photo->setLat($coords['lat']);
$photo->setLng($coords['lng']);
$photos[$key] = $photo;
}
return $this->json($photos);
}
#[Route('/spherical/by/gis/{gisId<[\w_]+>}', name: 'app_spherical_by_gis')]
public function byGis(
string $gisId,
EntityManagerInterface $em
): JsonResponse
{
$repo = $em->getRepository(SphericalPhoto::class);
$photos = $repo->findBySiteGis($gisId);
foreach ($photos as $key => $photo) {
$coords = $repo->coordinates($photo->getId());
$photo->setLat($coords['lat']);
$photo->setLng($coords['lng']);
$photos[$key] = $photo;
}
return $this->json($photos);
}
}