From e834445728ebf8827b9335116628ca02a94b4710 Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Wed, 22 Feb 2023 19:02:52 +0100 Subject: [PATCH 1/9] Add floorName to get_floor --- src/Controller/MapApiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index 626d846..2fb7683 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -99,7 +99,7 @@ class MapApiController extends AbstractController foreach ($place->getConnectedPlaces() as $cp) { foreach ($cp->getFloors() as $cf) { if (!$connectedFloors->contains($cf->getId())){ - $connectedFloors[] = $cf->getId(); + $connectedFloors[] = array('id' => $cf->getId(), 'name' => $cf->getName()); } } } From 9cee47b80a68cb12303360dacda7e492ea371c36 Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Wed, 22 Feb 2023 19:12:42 +0100 Subject: [PATCH 2/9] Add floorName to get_floor --- src/Controller/MapApiController.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index 2fb7683..f130314 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -94,22 +94,23 @@ class MapApiController extends AbstractController $jsonPlaces = array(); if ($representation == 'Cylinder' || $representation == 'PolySurface'){ foreach ($places as $place){ - $connectedFloors = new ArrayCollection(); - $connectedFloors[] = $floor->getId(); + $connectedFloors = array(); + $seen = new ArrayCollection(); + $seen[] = $floor->getId(); foreach ($place->getConnectedPlaces() as $cp) { foreach ($cp->getFloors() as $cf) { - if (!$connectedFloors->contains($cf->getId())){ + if (!$seen->contains($cf->getId())){ $connectedFloors[] = array('id' => $cf->getId(), 'name' => $cf->getName()); + $seen[] = $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' => $connectedFloors #$rep->getFloorsIdConnectedToPlaceID($place->getId()) // Will be added later ); } } From 4a0ad498d80bd4d07fb39844339d0e98ae6b28fb Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Wed, 22 Feb 2023 19:13:34 +0100 Subject: [PATCH 3/9] Update doc --- API.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/API.md b/API.md index 27c1d6b..a7b3c87 100644 --- a/API.md +++ b/API.md @@ -26,6 +26,13 @@ __The dict looks like :__ '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 + }, + {...} + ] }, {...} ] @@ -191,6 +198,30 @@ __Errors :__ - If _ID_ doesn't correspond to any registered edition : Return Error 404 "NotFoundHttpError". - If _ID_ has many occurence in the EditionRepository : Return Error 500 > The Database is corrupted. +--------------------- +### /api/map/get_site_name/ID +> Return the name of a site ID + +__Errors :__ +- If _ID_ doesn't correspond to any registered site : Return Error 404 "NotFoundHttpError". +- If _ID_ has many occurence in the EditionRepository : Return Error 500 > The Database is corrupted. + +--------------------- +### /api/map/get_building_name/ID +> Return the name of a building ID + +__Errors :__ +- If _ID_ doesn't correspond to any registered building : Return Error 404 "NotFoundHttpError". +- If _ID_ has many occurence in the EditionRepository : Return Error 500 > The Database is corrupted. + +--------------------- +### /api/map/get_floor_name/ID +> Return the name of a floor ID + +__Errors :__ +- If _ID_ doesn't correspond to any registered floor : Return Error 404 "NotFoundHttpError". +- If _ID_ has many occurence in the EditionRepository : Return Error 500 > The Database is corrupted. + --------------------- ### /api/map/del_place_name/PLACEID/NAME > Remove _NAME_ from the place _PLACEID_. From 8abdf2576a799e0698ff93333e80b29f67580e92 Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Tue, 28 Feb 2023 16:12:46 +0100 Subject: [PATCH 4/9] Debug get_floor who returned false connectedFloors --- src/Entity/Building.php | 2 +- src/Entity/Floor.php | 2 +- src/Entity/Site.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/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; From 33d15d44002c82cd6f557a5a5c8b67f390eac9b3 Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Tue, 28 Feb 2023 16:16:56 +0100 Subject: [PATCH 5/9] I forgot to ctrl S, ooopsiiiiiiiiii --- src/Controller/MapApiController.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index f130314..c0bd8da 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -95,14 +95,9 @@ class MapApiController extends AbstractController if ($representation == 'Cylinder' || $representation == 'PolySurface'){ foreach ($places as $place){ $connectedFloors = array(); - $seen = new ArrayCollection(); - $seen[] = $floor->getId(); - foreach ($place->getConnectedPlaces() as $cp) { - foreach ($cp->getFloors() as $cf) { - if (!$seen->contains($cf->getId())){ - $connectedFloors[] = array('id' => $cf->getId(), 'name' => $cf->getName()); - $seen[] = $cf->getId(); - } + foreach ($place->getFloors() as $f) { + if ($f->getId() != $id) { + $connectedFloors[] = array('id' => $f->getId(), 'name' => $f->getName()); } } $jsonPlaces[] = array( From 33677c9232687c8590bffc2c63d95f32bb478c48 Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Tue, 28 Feb 2023 16:38:18 +0100 Subject: [PATCH 6/9] Add B and S name for get_floor and return empty list if find_place_by_name doesn't find anything --- API.md | 17 +++++++++----- src/Controller/MapApiController.php | 35 +++++++++++++++-------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/API.md b/API.md index a7b3c87..2b712c1 100644 --- a/API.md +++ b/API.md @@ -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 diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index c0bd8da..0bb3b90 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -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); } From 68135b4567fd8ced332023461b28077f9de1ee3d Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Tue, 28 Feb 2023 16:42:31 +0100 Subject: [PATCH 7/9] Return empty list if there is no more edition instead of Error 404 --- API.md | 27 +-------------------------- src/Controller/MapApiController.php | 22 +++++++++------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/API.md b/API.md index 2b712c1..544a3eb 100644 --- a/API.md +++ b/API.md @@ -173,10 +173,9 @@ __Each edition is a dict :__ '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. --------------------- @@ -205,30 +204,6 @@ __Errors :__ - If _ID_ doesn't correspond to any registered edition : Return Error 404 "NotFoundHttpError". - If _ID_ has many occurence in the EditionRepository : Return Error 500 > The Database is corrupted. ---------------------- -### /api/map/get_site_name/ID -> Return the name of a site ID - -__Errors :__ -- If _ID_ doesn't correspond to any registered site : Return Error 404 "NotFoundHttpError". -- If _ID_ has many occurence in the EditionRepository : Return Error 500 > The Database is corrupted. - ---------------------- -### /api/map/get_building_name/ID -> Return the name of a building ID - -__Errors :__ -- If _ID_ doesn't correspond to any registered building : Return Error 404 "NotFoundHttpError". -- If _ID_ has many occurence in the EditionRepository : Return Error 500 > The Database is corrupted. - ---------------------- -### /api/map/get_floor_name/ID -> Return the name of a floor ID - -__Errors :__ -- If _ID_ doesn't correspond to any registered floor : Return Error 404 "NotFoundHttpError". -- If _ID_ has many occurence in the EditionRepository : Return Error 500 > The Database is corrupted. - --------------------- ### /api/map/del_place_name/PLACEID/NAME > Remove _NAME_ from the place _PLACEID_. diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index 0bb3b90..81b8ae2 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -182,19 +182,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); } From 679adf5bb4dd0693f10cee3bbeca6cb91b444a3c Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Tue, 28 Feb 2023 16:55:32 +0100 Subject: [PATCH 8/9] Add P,F,B,S names to find_place_by_name --- API.md | 13 +++++++++++-- src/Controller/MapApiController.php | 19 ++++++++----------- src/Entity/Place.php | 8 ++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/API.md b/API.md index 544a3eb..1c72ba7 100644 --- a/API.md +++ b/API.md @@ -99,9 +99,18 @@ __Format of the dict :__ [ { '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 + }, + {...} + ] }, {...} ] diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index 81b8ae2..2aa5245 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -94,18 +94,12 @@ class MapApiController extends AbstractController $jsonPlaces = array(); if ($representation == 'Cylinder' || $representation == 'PolySurface'){ foreach ($places as $place){ - $connectedFloors = array(); - foreach ($place->getFloors() as $f) { - if ($f->getId() != $id) { - $connectedFloors[] = array('id' => $f->getId(), 'name' => $f->getName()); - } - } $jsonPlaces[] = array( 'id' => $place->getId(), 'names' => $place->getJoinedNames(), 'type' => $place->getType(), 'surface' => $place->getTwoDRepresentation($representation, $floor->getAltitude()), - 'connectedFloors' => $connectedFloors #$rep->getFloorsIdConnectedToPlaceID($place->getId()) // Will be added later + 'connectedFloors' => $place->getFloorsNameAndId() #$rep->getFloorsIdConnectedToPlaceID($place->getId()) // Will be added later ); } } @@ -147,16 +141,19 @@ class MapApiController extends AbstractController { $result = array(); foreach ($rep->findPlaceByName($name) as $place){ - $floorsId = array(); + $floors = array(); foreach ($place->getFloors() as $floor) { - $floorsId[] = $floor->getId(); + $floors[] = $floor->getId(); } $building = $place->getFloors()[0]->getBuilding(); $result[] = array( - 'idRoom' => $place->getId(), + 'idPlace' => $place->getId(), + 'namePlace' => $place->getJoinedNames(), 'idSite' => $building->getSite()->getId(), + 'nameSite' => $building->getSite()->getName(), 'idBuilding' => $building->getId(), - 'idFloors' => $floorsId + 'nameBuilding' => $building->getName(), + 'floors' => $place->getFloorsNameAndId() ); } return $this->json($result); diff --git a/src/Entity/Place.php b/src/Entity/Place.php index 8c817d8..0e26a93 100644 --- a/src/Entity/Place.php +++ b/src/Entity/Place.php @@ -165,6 +165,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 { From b447a71d8952a1d2dce9e9796952ff3023fc0a72 Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Tue, 28 Feb 2023 17:20:24 +0100 Subject: [PATCH 9/9] Rename show_place_info into get_place_info --- API.md | 2 +- src/Controller/MapApiController.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 1c72ba7..915b319 100644 --- a/API.md +++ b/API.md @@ -150,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. diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index 2aa5245..abe38a8 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -160,8 +160,8 @@ class MapApiController extends AbstractController } - #[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.'); }