X-Git-Url: https://git.piment-noir.org/?p=Project_proches_de_moi-server.git;a=blobdiff_plain;f=src%2FController%2FPersonController.php;fp=src%2FController%2FPersonController.php;h=0430370f17f0b4380d0c03ed62fdffdf97e23be3;hp=9ef74692683fd17976ef9ed4619943d28ae63e6a;hb=8629835e06e50277f8868c19ea93f41313c16586;hpb=3d47ccc80097bec1a6890e103357d7c7cf0cff87 diff --git a/src/Controller/PersonController.php b/src/Controller/PersonController.php index 9ef7469..0430370 100644 --- a/src/Controller/PersonController.php +++ b/src/Controller/PersonController.php @@ -227,6 +227,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); }