Add sites endpoint
This commit is contained in:
parent
dc06764e36
commit
851808021a
@ -15,8 +15,42 @@ use Symfony\Bridge\Doctrine\Attribute\MapEntity;
|
||||
|
||||
class SiteController extends AbstractController
|
||||
{
|
||||
#[Route('/site/{gisId<\w+>}', name: 'app_site')]
|
||||
public function index(
|
||||
#[Route('/sites', name: 'app_site')]
|
||||
public function index(EntityManagerInterface $em): JsonResponse
|
||||
{
|
||||
$repo = $em->getRepository(Site::class);
|
||||
|
||||
$sites = $repo->findAll();
|
||||
|
||||
// TODO N+1...
|
||||
foreach($sites as $key => $site) {
|
||||
$coords = $repo->coordinates($site->getId());
|
||||
$site->setLat($coords['lat']);
|
||||
$site->setLng($coords['lng']);
|
||||
$sites[$key] = $site;
|
||||
$repo = $em->getRepository(Image::class);
|
||||
$images = new ArrayCollection(
|
||||
$repo->findBy(
|
||||
['site' => $site->getId()],
|
||||
['sequence' => 'ASC']
|
||||
)
|
||||
);
|
||||
$repo = $em->getRepository(Document::class);
|
||||
$documents = $repo->findBySite($site->getId());
|
||||
$repo = $em->getRepository(Bibliography::class);
|
||||
$bibliography = $repo->findAllBySite($site->getId());
|
||||
|
||||
$site->setImages($images);
|
||||
$site->setDocuments($documents);
|
||||
$site->setBibliography($bibliography);
|
||||
$repo = $em->getRepository(Site::class);
|
||||
}
|
||||
|
||||
return $this->json($sites);
|
||||
}
|
||||
|
||||
#[Route('/site/{gisId<\w+>}', name: 'app_site_record')]
|
||||
public function record(
|
||||
#[MapEntity(mapping: ['gisId' => 'gisId'])]
|
||||
Site $site,
|
||||
EntityManagerInterface $em
|
||||
|
Loading…
Reference in New Issue
Block a user