diff --git a/API.md b/API.md index 27c1d6b..915b319 100644 --- a/API.md +++ b/API.md @@ -19,13 +19,22 @@ __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 'names' : string[], //Names of the place, possibly empty, 'type': string, //in {'C'(orridor), 'S'(tairs), 'E'(levator), 'R'(oom)} , 'surface' : list of [int, int] //list of every points composing the room, projected on the floor surface + 'connectedFloors' : [ + { + 'id' : int, + 'name' : string + }, + {...} + ] }, {...} ] @@ -83,22 +92,31 @@ __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 [ { 'idPlace':int, //unique id of the place + 'namePlace':string[], //list of Names 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 + 'nameSite' : string, //name of the Site + 'idBuilding': int, //id of the Building + 'nameBuilding': string, //name of the Building + 'floors': [ //list of every {floorID, floorName} the place is in + { + 'name': string, //name of the first floor of the building + 'id' : int //its id + }, + {...} + ] }, {...} ] ``` -__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. --------------------- @@ -132,7 +150,7 @@ __Errors :__ --------------------- -### /api/map/show_place_info/ID +### /api/map/get_place_info/ID > Return a dict with main pieces of informations of the place ID. @@ -141,7 +159,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 :__ @@ -157,14 +176,17 @@ __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 } ``` -__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 :__ +- If there is no pending edition : Return Empty list +- 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 diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index 626d846..abe38a8 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -94,22 +94,12 @@ class MapApiController extends AbstractController $jsonPlaces = array(); if ($representation == 'Cylinder' || $representation == 'PolySurface'){ foreach ($places as $place){ - $connectedFloors = new ArrayCollection(); - $connectedFloors[] = $floor->getId(); - foreach ($place->getConnectedPlaces() as $cp) { - foreach ($cp->getFloors() as $cf) { - if (!$connectedFloors->contains($cf->getId())){ - $connectedFloors[] = $cf->getId(); - } - } - } - $connectedFloors->removeElement($floor->getId()); $jsonPlaces[] = array( 'id' => $place->getId(), 'names' => $place->getJoinedNames(), 'type' => $place->getType(), 'surface' => $place->getTwoDRepresentation($representation, $floor->getAltitude()), - 'connectedFloors' => $connectedFloors->toArray() #$rep->getFloorsIdConnectedToPlaceID($place->getId()) // Will be added later + 'connectedFloors' => $place->getFloorsNameAndId() #$rep->getFloorsIdConnectedToPlaceID($place->getId()) // Will be added later ); } } @@ -117,8 +107,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 ]); } @@ -145,29 +139,29 @@ 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){ + $floors = array(); + foreach ($place->getFloors() as $floor) { + $floors[] = $floor->getId(); } - return $this->json($all); + $building = $place->getFloors()[0]->getBuilding(); + $result[] = array( + 'idPlace' => $place->getId(), + 'namePlace' => $place->getJoinedNames(), + 'idSite' => $building->getSite()->getId(), + 'nameSite' => $building->getSite()->getName(), + 'idBuilding' => $building->getId(), + 'nameBuilding' => $building->getName(), + 'floors' => $place->getFloorsNameAndId() + ); } + return $this->json($result); } - #[Route('/api/map/show_place_info/{id}')] - public function show_place_info(PlaceRepository $rep, int $id): JsonResponse + #[Route('/api/map/get_place_info/{id}')] + public function get_place_info(PlaceRepository $rep, int $id): JsonResponse { $places = $rep->findPlaceById($id); if (sizeof($places) == 0) { throw new NotFoundHttpException('Error: '.$id.' doesn\'t correspond to any place.'); } @@ -185,19 +179,15 @@ class MapApiController extends AbstractController #[Route('/api/map/get_all_editions')] public function getEditions(EditionRepository $rep): JsonResponse { - $edits = $rep->getAllEditions(); - if (sizeof($edits)<1) { throw new NotFoundHttpException('Warning: There is no more edition to check.'); } - else { - $listEdits = array(); - foreach ($edits as $edit){ - $listEdits[] = array( - 'id' => $edit->getId(), - 'mode' => $edit->getMode(), - 'placeNames' => $edit->getEditedPlace()->getJoinedNames(), - 'placeId' => $edit->getEditedPlace()->getId(), - 'editorValue' => $edit->getValue() - ); - } + $listEdits = array(); + foreach ($rep->getAllEditions() as $edit){ + $listEdits[] = array( + 'id' => $edit->getId(), + 'mode' => $edit->getMode(), + 'placeNames' => $edit->getEditedPlace()->getJoinedNames(), + 'placeId' => $edit->getEditedPlace()->getId(), + 'editorValue' => $edit->getValue() + ); } return $this->json($listEdits); } diff --git a/src/Entity/Building.php b/src/Entity/Building.php index 18082e5..39e8df1 100644 --- a/src/Entity/Building.php +++ b/src/Entity/Building.php @@ -36,7 +36,7 @@ class Building } public function getName(): string - { return $this->id; + { return $this->name; } public function setName(string $name): self { $this->name = $name; diff --git a/src/Entity/Floor.php b/src/Entity/Floor.php index 9474ef0..785304b 100644 --- a/src/Entity/Floor.php +++ b/src/Entity/Floor.php @@ -39,7 +39,7 @@ class Floor } public function getName(): string - { return $this->id; + { return $this->name; } public function setName(string $name): self { $this->name = $name; diff --git a/src/Entity/Place.php b/src/Entity/Place.php index 1482a7c..9d62bbb 100644 --- a/src/Entity/Place.php +++ b/src/Entity/Place.php @@ -169,6 +169,14 @@ class Place } return $response; } + public function getFloorsNameAndId(): array + { + $response = array(); + foreach ($this->floors as $f) { + $response[] = array('id' => $f->getId(), 'name' => $f->getName()); + } + return $response; + } public function addFloor(Floor $floor): self { diff --git a/src/Entity/Site.php b/src/Entity/Site.php index 2faa798..c100150 100644 --- a/src/Entity/Site.php +++ b/src/Entity/Site.php @@ -37,7 +37,7 @@ class Site } public function getName(): string - { return $this->id; + { return $this->name; } public function setName(string $name): self { $this->name = $name;