Add image entity
This commit is contained in:
19
src/Controller/HomeController.php
Normal file
19
src/Controller/HomeController.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user