X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FController%2FPersonController.php;h=b037f5367faffa87ec7f2435f808f241526231eb;hb=787fc3b74e498cb78f516e372827790ba78920ac;hp=9ef74692683fd17976ef9ed4619943d28ae63e6a;hpb=3d47ccc80097bec1a6890e103357d7c7cf0cff87;p=Project_proches_de_moi-server.git diff --git a/src/Controller/PersonController.php b/src/Controller/PersonController.php index 9ef7469..b037f53 100644 --- a/src/Controller/PersonController.php +++ b/src/Controller/PersonController.php @@ -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(); @@ -227,6 +230,52 @@ class PersonController extends FOSRestController return $persons; } + /** + * @Rest\Put( + * path = "/api/person/{id}/online", + * name = "set_person_online" + * ) + * @Rest\View(StatusCode = Response::HTTP_CREATED) + */ + public function onlinePersonAction(Request $request) + { + //TODO: check that the authenticated user have the same id + $em = $this->getDoctrine()->getManager(); + $person = $em->getRepository('App:Person')->find($request->get('id')); + + if (empty($person)) { + return $this->PersonNotFound(); + } + + $person->setOnline(true); + + $em->merge($person); + $em->flush(); + } + + /** + * @Rest\Put( + * path = "/api/person/{id}/offline", + * name = "set_person_offline" + * ) + * @Rest\View(StatusCode = Response::HTTP_CREATED) + */ + public function offlinePersonAction(Request $request) + { + //TODO: check that the authenticated user have the same id + $em = $this->getDoctrine()->getManager(); + $person = $em->getRepository('App:Person')->find($request->get('id')); + + if (empty($person)) { + return $this->PersonNotFound(); + } + + $person->setOnline(false); + + $em->merge($person); + $em->flush(); + } + private function PersonNotFound() { return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND); }