From 4c4feb3e3193703f6cfa44ca711092a8acb38329 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 28 Jun 2018 10:30:12 +0200 Subject: [PATCH] Add REST ressource to get a person localisation. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/Controller/PersonController.php | 20 ++++++++++++++++++++ src/Entity/Person.php | 2 -- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Controller/PersonController.php b/src/Controller/PersonController.php index 7853771..b452c63 100644 --- a/src/Controller/PersonController.php +++ b/src/Controller/PersonController.php @@ -82,6 +82,26 @@ class PersonController extends Controller } + /** + * @Rest\Get("/api/person/{id}/localisations") + */ + public function getLocalisationActions(Request $request) + { + $em = $this->getDoctrine()->getManager(); + $localisations = $em->getRepository('App:Localisation')->findBy(['person_id' => $request->get('id')]); + + if (empty($localisations)) { + return View::create(['message' => 'Person localisation not found'], Response::HTTP_NOT_FOUND); + } + + $view = View::create($localisation); + $view->setFormat('json'); + + $viewHandler = $this->get('fos_rest.view_handler'); + return $viewHandler->handle($view); + + } + /** * @Rest\Post("/api/person/{id}/localisation") * @Rest\View(StatusCode = Response::HTTP_CREATED) diff --git a/src/Entity/Person.php b/src/Entity/Person.php index 934b2be..d401cc3 100644 --- a/src/Entity/Person.php +++ b/src/Entity/Person.php @@ -3,8 +3,6 @@ namespace App\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; -use JMS\Serializer\Annotation\ExclusionPolicy; -use JMS\Serializer\Annotation\Expose; /** * @ORM\Entity() -- 2.34.1