From 68135b4567fd8ced332023461b28077f9de1ee3d Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Tue, 28 Feb 2023 16:42:31 +0100 Subject: [PATCH] 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); }