Add BuildingTech
This commit is contained in:
41
src/Controller/BuildingTechController.php
Normal file
41
src/Controller/BuildingTechController.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\BuildingTech;
|
||||
|
||||
class BuildingTechController extends AbstractController
|
||||
{
|
||||
#[Route('/building_techs', name: 'app_techs')]
|
||||
public function index(EntityManagerInterface $em): JsonResponse
|
||||
{
|
||||
$repo = $em->getRepository(BuildingTech::class);
|
||||
$techs = $repo->findAll();
|
||||
|
||||
//dd($techs);
|
||||
|
||||
foreach($techs as $key => $tech) {
|
||||
$coords = $repo->coordinates($tech->getId());
|
||||
$tech->setLat($coords['lat']);
|
||||
$tech->setLng($coords['lng']);
|
||||
$techs[$key] = $tech;
|
||||
}
|
||||
|
||||
return $this->json($techs);
|
||||
}
|
||||
|
||||
#[Route('/building_techs/{id<\d+>}', name: 'app_tech')]
|
||||
public function record(BuildingTech $finding, EntityManagerInterface $em): JsonResponse
|
||||
{
|
||||
$repo = $em->getRepository(BuildingTech::class);
|
||||
$coords = $repo->coordinates($finding->getId());
|
||||
$finding->setLat($coords['lat']);
|
||||
$finding->setLng($coords['lng']);
|
||||
|
||||
return $this->json($finding);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user