Add Reuse endpoint

This commit is contained in:
2025-08-08 11:13:13 +02:00
parent 660d409093
commit 875ca03568
3 changed files with 106 additions and 45 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Controller;
use App\Entity\Reuse;
use App\Entity\Bibliography;
use App\Entity\Image;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
class ReuseController extends AbstractController
{
#[Route('/reuse', name: 'app_reuse')]
public function index(EntityManagerInterface $em): JsonResponse
{
$repo = $em->getRepository(Reuse::class);
//$repoBib = $em->getRepository(Bibliography::class);
$repoImg = $em->getRepository(Image::class);
$records = $repo->findBy([], ['label' => 'ASC']);
// Terrible? N+1..
foreach ($records as $key => $record) {
$id = $record->getId();
$record->setLat($repo->coordinates($id)['lat']);
$record->setLng($repo->coordinates($id)['lng']);
//$biblio = $repoBib->findAllByNotConserved($id);
//$record->setBibliographies($biblio);
$images = $repoImg->findBy(
['reuse' => $record->getId()],
['sequence' => 'ASC']
);
$record->setImages($images);
$records[$key] = $record;
}
return $this->json([
'message' => 'All records for reused assets',
'records' => $records
],
);
}
}

View File

@@ -37,6 +37,9 @@ class Image implements \JsonSerializable
#[ORM\Column(name: 'affioramento', type: Types::BIGINT, nullable: true)]
private ?string $prehistoric = null;
#[ORM\Column(name: 'reimpiego', type: Types::BIGINT, nullable: true)]
private ?string $reuse = null;
#[ORM\Column(name: 'ordine', type: Types::SMALLINT)]
private ?int $sequence = null;
@@ -139,6 +142,18 @@ class Image implements \JsonSerializable
return $this;
}
public function getReuse(): ?string
{
return $this->prehistoric;
}
public function setReuse(?string $reuse): static
{
$this->reuse = $reuse;
return $this;
}
public function getSequence(): ?int
{
return $this->sequence;