Add Reuse endpoint
This commit is contained in:
46
src/Controller/ReuseController.php
Normal file
46
src/Controller/ReuseController.php
Normal 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
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user