Add GeoImage endpoints
This commit is contained in:
parent
e98cbc585b
commit
72af052651
@ -10,7 +10,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class GeoImageController extends AbstractController
|
||||
{
|
||||
#[Route('/geoimage', name: 'app_geo_image')]
|
||||
#[Route('/geoimages', name: 'app_geo_images')]
|
||||
public function index(EntityManagerInterface $em): JsonResponse
|
||||
{
|
||||
$repo = $em->getRepository(GeoImage::class);
|
||||
@ -18,4 +18,19 @@ class GeoImageController extends AbstractController
|
||||
|
||||
return $this->json($geoImages);
|
||||
}
|
||||
|
||||
#[Route('/geoimages/menu', name: 'app_geo_image_menu')]
|
||||
public function menu(EntityManagerInterface $em): JsonResponse
|
||||
{
|
||||
$repo = $em->getRepository(GeoImage::class);
|
||||
$geoImages = $repo->findLabelsAndIds();
|
||||
|
||||
return $this->json($geoImages);
|
||||
}
|
||||
|
||||
#[Route('/geoimages/{id}', name: 'app_geo_image_record')]
|
||||
public function record(GeoImage $geoImage): JsonResponse
|
||||
{
|
||||
return $this->json($geoImage);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ class GeoImage implements JsonSerializable
|
||||
#[ORM\Column(type: Types::JSON, name: 'poligono')]
|
||||
private ?string $polygon = null;
|
||||
|
||||
#[ORM\Column(length: 60, name: 'etichetta')]
|
||||
private ?string $label = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@ -58,11 +61,25 @@ class GeoImage implements JsonSerializable
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->polygon;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): static
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'filename' => $this->filename,
|
||||
'polygon' => $this->polygon,
|
||||
'label' => $this->label,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,9 @@ namespace App\Repository;
|
||||
|
||||
use App\Entity\GeoImage;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\DBAL\LockMode;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Override;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<GeoImage>
|
||||
@ -16,6 +18,34 @@ class GeoImageRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, GeoImage::class);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function find(mixed $id, LockMode|int|null $lockMode = null, ?int $lockVersion = null): ?object
|
||||
{
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
$sql = "SELECT
|
||||
id,
|
||||
filename,
|
||||
etichetta as label,
|
||||
ST_AsGeoJSON(poligono) as polygon
|
||||
FROM geo_immagine_catasto
|
||||
WHERE id = :id
|
||||
";
|
||||
|
||||
$result = $conn->executeQuery($sql, ['id' => $id])
|
||||
->fetchAssociative();
|
||||
|
||||
if (! $result) return null;
|
||||
|
||||
$geoImage = new GeoImage();
|
||||
$geoImage->setId($result['id']);
|
||||
$geoImage->setFilename($result['filename']);
|
||||
$geoImage->setPolygon($result['polygon']);
|
||||
$geoImage->setLabel($result['label']);
|
||||
|
||||
return $geoImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all geoimages with associated geometry (polygon)
|
||||
* as GeoJSON
|
||||
@ -28,8 +58,10 @@ class GeoImageRepository extends ServiceEntityRepository
|
||||
$sql = "SELECT
|
||||
id,
|
||||
filename,
|
||||
etichetta as label,
|
||||
ST_AsGeoJSON(poligono) as polygon
|
||||
FROM geo_immagine_catasto
|
||||
ORDER BY etichetta ASC
|
||||
";
|
||||
|
||||
$results = $conn->executeQuery($sql)
|
||||
@ -41,6 +73,35 @@ class GeoImageRepository extends ServiceEntityRepository
|
||||
$geoimage->setId($result['id']);
|
||||
$geoimage->setFilename($result['filename']);
|
||||
$geoimage->setPolygon($result['polygon']);
|
||||
$geoimage->setLabel($result['label']);
|
||||
$entities[] = $geoimage;
|
||||
}
|
||||
|
||||
return $entities;
|
||||
}
|
||||
/**
|
||||
* Returns all labels and ids for menu
|
||||
* @return GeoImage[]
|
||||
*/
|
||||
public function findLabelsAndIds()
|
||||
{
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
$sql = "SELECT
|
||||
id,
|
||||
etichetta as label
|
||||
FROM geo_immagine_catasto
|
||||
ORDER BY etichetta ASC
|
||||
";
|
||||
|
||||
$results = $conn->executeQuery($sql)
|
||||
->fetchAllAssociative();
|
||||
|
||||
$entities = [];
|
||||
foreach ($results as $result) {
|
||||
$geoimage = new GeoImage();
|
||||
$geoimage->setId($result['id']);
|
||||
$geoimage->setLabel($result['label']);
|
||||
$entities[] = $geoimage;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user