Only expose relevant attributes.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 28 Jun 2018 11:52:46 +0000 (13:52 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 28 Jun 2018 11:52:46 +0000 (13:52 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/Controller/PersonController.php
src/Entity/Friendship.php
src/Entity/Localisation.php
src/Entity/Person.php

index d4bd7ff374204dc15b14c68f3ec21e7f6d096bd3..734f29c9eca165ade74de8773ffde5970a07cb1a 100644 (file)
@@ -3,7 +3,6 @@ namespace App\Controller;
 
 use App\Entity\Person;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 
 use App\Entity\Person;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-#use FOS\RestBundle\Controller\FOSRestController;
 use FOS\RestBundle\Controller\Annotations as Rest;
 use FOS\RestBundle\View\ViewHandler;
 use FOS\RestBundle\View\View;
 use FOS\RestBundle\Controller\Annotations as Rest;
 use FOS\RestBundle\View\ViewHandler;
 use FOS\RestBundle\View\View;
@@ -16,7 +15,7 @@ class PersonController extends Controller
 {
     /**
      * @Rest\Post(
 {
     /**
      * @Rest\Post(
-     *     path = "/person/inscription",
+     *     path = "/api/person/inscription",
      *     name = "create_person"
      * )
      * @Rest\View(StatusCode = Response::HTTP_CREATED)
      *     name = "create_person"
      * )
      * @Rest\View(StatusCode = Response::HTTP_CREATED)
@@ -75,23 +74,32 @@ class PersonController extends Controller
     }
 
     /**
     }
 
     /**
-     * @Rest\Get("/api/person/{id}/friends/localisation")
+     * @Rest\Get("/api/person/{id}/localisations")
+     * @Rest\View()
      */
      */
-    public function getFriendsLocalisationAction(Request $request)
+    public function getLocalisationsAction(Request $request)
     {
     {
+        $em = $this->getDoctrine()->getManager();
+        $localisations = $em->getRepository('App:Localisation')->findBy(['person' => $request->get('id')]);
 
 
+        if (empty($localisations)) {
+            return $this->PersonLocalisationsNotFound();
+        }
+
+        return $localisations;
     }
 
     /**
     }
 
     /**
-     * @Rest\Get("/api/person/{id}/localisations")
+     * @Rest\Get("/api/person/{id}/localisation")
+     * @Rest\View()
      */
      */
-    public function getLocalisationsAction(Request $request)
+    public function getLocalisationAction(Request $request)
     {
         $em = $this->getDoctrine()->getManager();
     {
         $em = $this->getDoctrine()->getManager();
-        $localisations = $em->getRepository('App:Localisation')->findBy(['person' => $request->get('id')]);
+        $localisations = $em->getRepository('App:Localisation')->findOneBy(['person' => $request->get('id')]);
 
         if (empty($localisations)) {
 
         if (empty($localisations)) {
-            return $this->PersonLocalisationsNotFound();
+            return $this->PersonLocalisationNotFound();
         }
 
         return $localisations;
         }
 
         return $localisations;
@@ -188,7 +196,7 @@ class PersonController extends Controller
        $persons = $em->getRepository('App:Person')->findAll();
 
        if (empty($persons)) {
        $persons = $em->getRepository('App:Person')->findAll();
 
        if (empty($persons)) {
-           return $this->PersonNotFound();
+           return $this->PersonsNotFound();
        }
 
        return $persons;
        }
 
        return $persons;
@@ -218,6 +226,14 @@ class PersonController extends Controller
      return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
  }
 
      return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
  }
 
+ private function PersonsNotFound() {
+     return View::create(['message' => 'Persons not found'], Response::HTTP_NOT_FOUND);
+ }
+
+ private function PersonLocalisationNotFound() {
+     return View::create(['message' => 'Person localisation not found'], Response::HTTP_NOT_FOUND);
+ }
+
  private function PersonLocalisationsNotFound() {
      return View::create(['message' => 'Person localisations not found'], Response::HTTP_NOT_FOUND);
  }
  private function PersonLocalisationsNotFound() {
      return View::create(['message' => 'Person localisations not found'], Response::HTTP_NOT_FOUND);
  }
index a069bceca52184cd28ee1a3b6418f47fe2721db9..444523f5b3d50513c2faad00aecf1453f51787d4 100644 (file)
@@ -2,10 +2,12 @@
 namespace App\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
 namespace App\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
+use JMS\Serializer\Annotation as Serializer;
 
 /**
  * @ORM\Entity()
  * @ORM\Table(name="Friendship");
 
 /**
  * @ORM\Entity()
  * @ORM\Table(name="Friendship");
+ * @Serializer\ExclusionPolicy("all")
  */
 class Friendship
 {
  */
 class Friendship
 {
@@ -18,11 +20,13 @@ class Friendship
     /**
      * @ORM\Id
      * @ORM\ManyToOne(targetEntity="Person", inversedBy="friends_with_me", cascade={"all"})
     /**
      * @ORM\Id
      * @ORM\ManyToOne(targetEntity="Person", inversedBy="friends_with_me", cascade={"all"})
+     * @Serializer\Expose
      */
     protected $friend;
 
     /**
      * @ORM\Column(type="boolean", options={"default":false})
      */
     protected $friend;
 
     /**
      * @ORM\Column(type="boolean", options={"default":false})
+     * @Serializer\Expose
      */
     protected $is_valid;
 
      */
     protected $is_valid;
 
index 69431b97640b426183700232cd9f7bbc4a5f677d..b85a705bca5acfb4d1a2a3c202df708ec2feca62 100644 (file)
@@ -2,10 +2,12 @@
 namespace App\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
 namespace App\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
+use JMS\Serializer\Annotation as Serializer;
 
 /**
  * @ORM\Entity()
  * @ORM\Table(name="Localisation")
 
 /**
  * @ORM\Entity()
  * @ORM\Table(name="Localisation")
+ * @Serializer\ExclusionPolicy("all")
  */
 class Localisation
 {
  */
 class Localisation
 {
@@ -23,16 +25,19 @@ class Localisation
 
     /**
      * @ORM\Column(type="datetime")
 
     /**
      * @ORM\Column(type="datetime")
+     * @Serializer\Expose
      */
     protected $timestamp;
 
     /**
      * @ORM\Column(type="float")
      */
     protected $timestamp;
 
     /**
      * @ORM\Column(type="float")
+     * @Serializer\Expose
      */
     protected $latitude;
 
     /**
      * @ORM\Column(type="float")
      */
     protected $latitude;
 
     /**
      * @ORM\Column(type="float")
+     * @Serializer\Expose
      */
     protected $longitude;
 
      */
     protected $longitude;
 
index d401cc32432f16311220f818c8a775440b4729dc..d06f5756f9ce2a8ce1b2e981ae1b01e0e92d397c 100644 (file)
@@ -3,11 +3,13 @@ namespace App\Entity;
 
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
+use JMS\Serializer\Annotation as Serializer;
 
 /**
  * @ORM\Entity()
  * @ORM\Table(name="Person", indexes={@ORM\Index(name="authentification_idx", columns={"email", "password"}),
  *                                    @ORM\Index(name="search_idx", columns={"firstname", "lastname", "email"})});
 
 /**
  * @ORM\Entity()
  * @ORM\Table(name="Person", indexes={@ORM\Index(name="authentification_idx", columns={"email", "password"}),
  *                                    @ORM\Index(name="search_idx", columns={"firstname", "lastname", "email"})});
+ * @Serializer\ExclusionPolicy("all")
  */
 class Person
 {
  */
 class Person
 {
@@ -15,21 +17,25 @@ class Person
      * @ORM\Id
      * @ORM\Column(type="bigint")
      * @ORM\GeneratedValue(strategy="AUTO")
      * @ORM\Id
      * @ORM\Column(type="bigint")
      * @ORM\GeneratedValue(strategy="AUTO")
+     * @Serializer\Expose
      */
     protected $id;
 
     /**
      * @ORM\Column(type="string")
      */
     protected $id;
 
     /**
      * @ORM\Column(type="string")
+     * @Serializer\Expose
      */
     protected $firstname;
 
     /**
      * @ORM\Column(type="string")
      */
     protected $firstname;
 
     /**
      * @ORM\Column(type="string")
+     * @Serializer\Expose
      */
     protected $lastname;
 
     /**
      * @ORM\Column(type="string", unique=true)
      */
     protected $lastname;
 
     /**
      * @ORM\Column(type="string", unique=true)
+     * @Serializer\Expose
      */
     protected $email;
 
      */
     protected $email;
 
@@ -40,6 +46,7 @@ class Person
 
     /**
      * @ORM\Column(type="boolean", options={"default":false})
 
     /**
      * @ORM\Column(type="boolean", options={"default":false})
+     * @Serializer\Expose
      */
     protected $online;
 
      */
     protected $online;