Add image entity

This commit is contained in:
2024-11-15 10:02:58 +01:00
parent 325e255d75
commit b1c9fdbdf7
6 changed files with 256 additions and 14 deletions

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController
{
#[Route('/', name: 'app_home')]
public function index(): JsonResponse
{
return $this->json([
'message' => 'Path not found',
'status' => 404
], 404);
}
}

View File

@@ -3,6 +3,9 @@
namespace App\Controller;
use App\Entity\Site;
use App\Entity\Image;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
@@ -10,24 +13,27 @@ use Symfony\Bridge\Doctrine\Attribute\MapEntity;
class SiteController extends AbstractController
{
#[Route('/', name: 'app_home')]
public function root(): JsonResponse
{
return $this->json([
'message' => 'Path not found',
'status' => 404
], 404);
}
#[Route('/site/{gisId<\w+>}', name: 'app_site')]
public function index(
#[MapEntity(mapping: ['gisId' => 'gisId'])]
Site $site
Site $site,
EntityManagerInterface $em
): JsonResponse
{
return $this->json([
'message' => 'Request successful',
'site' => $site,
]);
$repo = $em->getRepository(Site::class);
$coords = $repo->coordinates($site->getId());
$repo = $em->getRepository(Image::class);
$images = new ArrayCollection(
$repo->findBy(
['site' => $site->getId()],
['sequence' => 'DESC']
)
);
$site->setImages($images);
$site->setLat((float) $coords['lat']);
$site->setLng((float) $coords['lng']);
return $this->json( $site );
}
}