Fix the REST ressource for getting the latest localisation of a user.
[Project_proches_de_moi-server.git] / src / Controller / PersonController.php
index 0430370f17f0b4380d0c03ed62fdffdf97e23be3..b037f5367faffa87ec7f2435f808f241526231eb 100644 (file)
@@ -132,7 +132,10 @@ class PersonController extends FOSRestController
     {
         //TODO: Check that the authenticated user is allowed to see the localisation
         $em = $this->getDoctrine()->getManager();
-        $localisation = $em->getRepository('App:Localisation')->findOneBy(['person' => $request->get('id')]);
+
+        $query = $em->createQuery("SELECT l1 FROM App\Entity\Localisation l1 WHERE l1.person = :person and l1.timestamp = (SELECT MAX(l2.timestamp) FROM App\Entity\Localisation l2 WHERE l2.person = l1.person)");
+        $query->setParameter('person', $request->get('id'));
+        $localisation = $query->getResult();
 
         if (empty($localisation)) {
             return $this->PersonLocalisationNotFound();