Add B and S name for get_floor and return empty list if find_place_by_name doesn't find anything

This commit is contained in:
Kouril42 2023-02-28 16:38:18 +01:00
parent 33d15d4400
commit 33677c9232
2 changed files with 30 additions and 22 deletions

17
API.md
View File

@ -19,7 +19,9 @@ __The dict looks like :__
```json
{
'idSite' : int, //id of the Site
'nameSite' : string, //name of the Site
'idBuilding': int, //id of the Building
'nameBuilding': string, //name of the Building
'places : [
{
'id': int, //unique id
@ -90,7 +92,7 @@ __The json will look like :__
---------------------
### /api/map/find_place_by_name/NAME
>Return a dict representing the list of places with NAME.
> Return a list of dict representing all places with NAME.
__Format of the dict :__
```json
@ -104,8 +106,8 @@ __Format of the dict :__
{...}
]
```
__Errors :__
- If _NAME_ doesn't correspond to any registered place : Return Error 404 "NotFoundHttpError".
__Notes :__
- If _NAME_ doesn't correspond to any registered place : Return an Empty list.
---------------------
@ -148,7 +150,8 @@ __Format of the dict :__
{
'idPlace': int,
'names': string[], // list of names for this place
'users': string[] // list of users' name (professors, etc)
'users': string[], // list of users' name (professors, etc)
'floors' : int[] // list of floorIds the place is connected.
}
```
__Errors :__
@ -164,7 +167,7 @@ __Each edition is a dict :__
```json
{
'id': int // id of the edition,
'mode': string, // should be AddName, RemoveName, AddUser or RemoveUser
'mode': string, // could be add_place_name, del_place_name, add_room_user_name or del_room_user_name
'placeNames': string[], // list of names of the place
'placeId': string, // id of the place
'editorValue': string // the value to add or remove
@ -172,6 +175,10 @@ __Each edition is a dict :__
```
__Errors :__
- If there is no pending edition : Return Error 404 "NotFoundHttpError" > It's a Warning that is not fatal (but I didn't manage to raise a warning with symfony so it's still an error)
__Notes :__
- The strings in mode are transparent to the API so the given names are only an advice. The only rules is to set adequaly create_edition and the treatment of editions.
---------------------
### /api/map/create_edition/MODE/PLACEID/VALUE

View File

@ -113,8 +113,12 @@ class MapApiController extends AbstractController
return $this->json("Error on represantation attribute");
}
$building = $floor->getBuilding();
return $this->json(['idSite' => $building->getSite()->getId(),
return $this->json([
'name' => $floor->getName(),
'idSite' => $building->getSite()->getId(),
'nameSite' => $building->getSite()->getName(),
'idBuilding' => $building->getId(),
'nameBuilding' => $building->getName(),
'places' => $jsonPlaces
]);
}
@ -141,24 +145,21 @@ class MapApiController extends AbstractController
#[Route('/api/map/find_place_by_name/{name}')]
public function find_place_by_name(PlaceRepository $rep, string $name): JsonResponse
{
$places = $rep->findPlaceByName($name);
if (sizeof($places)==0){ throw new NotFoundHttpException('Error: \''.$name.'\' doesn\'t correspond to any placeName.'); }
else {
$all = array();
foreach ($places as $place){
$floorsId = array();
foreach ($place->getFloors() as $floor) {
$floorsId[] = $floor->getId();
}
$building = $place->getFloors()[0]->getBuilding();
$all[] = array('idRoom' => $place->getId(),
'idSite' => $building->getSite()->getId(),
'idBuilding' => $building->getId(),
'idFloors' => $floorsId
);
$result = array();
foreach ($rep->findPlaceByName($name) as $place){
$floorsId = array();
foreach ($place->getFloors() as $floor) {
$floorsId[] = $floor->getId();
}
return $this->json($all);
$building = $place->getFloors()[0]->getBuilding();
$result[] = array(
'idRoom' => $place->getId(),
'idSite' => $building->getSite()->getId(),
'idBuilding' => $building->getId(),
'idFloors' => $floorsId
);
}
return $this->json($result);
}