mirror of
https://gitlab.aliens-lyon.fr/encartes/backend.git
synced 2026-09-11 16:50:46 +02:00
Add idBuilding & idSite to find_place_by_name + create get_?_name for building, site & floor
This commit is contained in:
@@ -17,6 +17,7 @@ use Exception;
|
||||
|
||||
|
||||
use App\Repository\SiteRepository;
|
||||
use App\Repository\BuildingRepository;
|
||||
use App\Repository\FloorRepository;
|
||||
use App\Repository\PlaceRepository;
|
||||
use App\Repository\PlaceNameRepository;
|
||||
@@ -53,6 +54,33 @@ class MapApiController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/api/map/get_site_name/{id}')]
|
||||
public function get_site_name(SiteRepository $rep, int $id): JsonResponse
|
||||
{
|
||||
$sites = $rep->findSiteById($id);
|
||||
if (sizeof($sites) == 0) { throw new NotFoundHttpException('Error: '.$id.' doesn\'t correspond to any place.'); }
|
||||
elseif (sizeof($sites)>1) { throw new Exception('Internal Error: '.$id.' refers to more than one siteId ; the BDD is corrupted.'); }
|
||||
return $this->json($sites[0]->getName());
|
||||
}
|
||||
|
||||
#[Route('/api/map/get_building_name/{id}')]
|
||||
public function get_building_name(BuildingRepository $rep, int $id): JsonResponse
|
||||
{
|
||||
$buildings = $rep->findBuildingById($id);
|
||||
if (sizeof($buildings) == 0) { throw new NotFoundHttpException('Error: '.$id.' doesn\'t correspond to any place.'); }
|
||||
elseif (sizeof($buildings)>1) { throw new Exception('Internal Error: '.$id.' refers to more than one buildingId ; the BDD is corrupted.'); }
|
||||
return $this->json($buildings[0]->getName());
|
||||
}
|
||||
|
||||
#[Route('/api/map/get_floor_name/{id}')]
|
||||
public function get_floor_name(FloorRepository $rep, int $id): JsonResponse
|
||||
{
|
||||
$floors = $rep->findFloorById($id);
|
||||
if (sizeof($floors) == 0) { throw new NotFoundHttpException('Error: '.$id.' doesn\'t correspond to any place.'); }
|
||||
elseif (sizeof($floors)>1) { throw new Exception('Internal Error: '.$id.' refers to more than one floorId ; the BDD is corrupted.'); }
|
||||
return $this->json($floors[0]->getName());
|
||||
}
|
||||
|
||||
#[Route('/api/map/get_floor/{id}/{representation}')]
|
||||
public function get_floor(FloorRepository $rep, int $id, string $representation='Cylinder'): JsonResponse
|
||||
{
|
||||
@@ -111,7 +139,12 @@ class MapApiController extends AbstractController
|
||||
foreach ($place->getFloors() as $floor) {
|
||||
$floorsId[] = $floor->getId();
|
||||
}
|
||||
$all[] = array('idRoom' => $place->getId(), 'idFloors' => $floorsId);
|
||||
$building = $floorsId[0]->getBuilding();
|
||||
$all[] = array('idRoom' => $place->getId(),
|
||||
'idSite' => $building->getSite()->getId(),
|
||||
'idBuilding' => $building->getId(),
|
||||
'idFloors' => $floorsId
|
||||
);
|
||||
}
|
||||
return $this->json($all);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user