Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
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;
- * 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)
- * @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();
$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 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);
}
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")
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Person", inversedBy="friends_with_me", cascade={"all"})
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Person", inversedBy="friends_with_me", cascade={"all"})
*/
protected $friend;
/**
* @ORM\Column(type="boolean", options={"default":false})
*/
protected $friend;
/**
* @ORM\Column(type="boolean", options={"default":false})
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")
/**
* @ORM\Column(type="datetime")
/**
* @ORM\Column(type="datetime")
*/
protected $timestamp;
/**
* @ORM\Column(type="float")
*/
protected $timestamp;
/**
* @ORM\Column(type="float")
*/
protected $latitude;
/**
* @ORM\Column(type="float")
*/
protected $latitude;
/**
* @ORM\Column(type="float")
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")
* @ORM\Id
* @ORM\Column(type="bigint")
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Id
* @ORM\Column(type="bigint")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $firstname;
/**
* @ORM\Column(type="string")
*/
protected $firstname;
/**
* @ORM\Column(type="string")
*/
protected $lastname;
/**
* @ORM\Column(type="string", unique=true)
*/
protected $lastname;
/**
* @ORM\Column(type="string", unique=true)
/**
* @ORM\Column(type="boolean", options={"default":false})
/**
* @ORM\Column(type="boolean", options={"default":false})