Add REST ressource to get a person localisation.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 28 Jun 2018 08:30:12 +0000 (10:30 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 28 Jun 2018 08:30:12 +0000 (10:30 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/Controller/PersonController.php
src/Entity/Person.php

index 785377114530cfea5c1a353db4b3fc156ef18053..b452c6360093b108b2f42b373311d7bf5cd42381 100644 (file)
@@ -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)
index 934b2be550db9866fda3b712ed807ae994ae6da4..d401cc32432f16311220f818c8a775440b4729dc 100644 (file)
@@ -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()