Add idBuilding & idSite to find_place_by_name + create get_?_name for building, site & floor

This commit is contained in:
Kouril42 2023-02-19 12:23:28 +01:00
parent a57adb9883
commit e3f16127af
4 changed files with 103 additions and 7 deletions

41
API.md
View File

@ -76,18 +76,53 @@ __The json will look like :__
---------------------
### /api/map/find_place_by_name/NAME
>Return a dict representing the place with NAME.
>Return a dict representing the list of places with NAME.
__Format of the dict :__
```json
[
{
'idPlace':int, //unique id of the place
'idSite': int, //id of the place Site
'idBuilding': int, //id of the place Building
'idFloors': int[] //list of every floorID the place is in
}
},
{...}
]
```
__Errors :__
- If _NAME_ doesn't correspond to any registered place : Return Error 404 "NotFoundHttpError".
- If _NAME_ has many occurence in the PlaceNameRepository : Return Error 500 "UnprocessableEntityHttpException" > The API can't decide which place should be provided.
---------------------
### /api/map/get_site_name/ID
> Return the name of the Site ID.
__Errors :__
- If _ID_ doesn't correspond to any registered Site : Return Error 404 "NotFoundHttpError".
- If _ID_ has many occurence in the SiteRepository : Return Error 500 > The Database is corrupted.
---------------------
### /api/map/get_building_name/ID
> Return the name of the Building ID.
__Errors :__
- If _ID_ doesn't correspond to any registered Building : Return Error 404 "NotFoundHttpError".
- If _ID_ has many occurence in the BuildingRepository : Return Error 500 > The Database is corrupted.
---------------------
### /api/map/get_floor_name/ID
> Return the name of the Floor ID.
__Errors :__
- If _ID_ doesn't correspond to any registered Floor : Return Error 404 "NotFoundHttpError".
- If _ID_ has many occurence in the FloorRepository : Return Error 500 > The Database is corrupted.
---------------------
### /api/map/show_place_info/ID

View File

@ -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);
}

View File

@ -39,6 +39,20 @@ class BuildingRepository extends ServiceEntityRepository
}
}
/**
* @return Building[] Returns an array of Building objects
*/
public function findBuildingById(int $id): array
{
return $this->createQueryBuilder('b')
->andWhere('b.id = :val')
->setParameter('val', $id)
->orderBy('b.id', 'ASC')
->getQuery()
->getResult()
;
}
// /**
// * @return Building[] Returns an array of Building objects
// */

View File

@ -44,6 +44,20 @@ class SiteRepository extends ServiceEntityRepository
return $this->createQueryBuilder('s')->orderBy('s.id','ASC')->getQuery()->getResult();
}
/**
* @return Site[] Returns an array of Site objects
*/
public function findSiteById(int $id): array
{
return $this->createQueryBuilder('s')
->andWhere('s.id = :val')
->setParameter('val', $id)
->orderBy('s.id', 'ASC')
->getQuery()
->getResult()
;
}
// /**
// * @return Site[] Returns an array of Site objects
// */