getDoctrine()->getManager(); $em->persist($person); $em->flush(); return $this->view($person, Response::HTTP_CREATED, ['Location' => $this->generateUrl('show_person', ['id' => $person->getId(), UrlGeneratorInterface::ABSOLUTE_URL])]); } /** * @Rest\Delete("/person/{id}") * @Rest\View(statusCode = Response::HTTP_NO_CONTENT) */ public function removePersonAction(Request $request) { $em = $this->getDoctrine()->getManager(); $person = $em->getRepository('App:Person')->find($request->get('id')); if ($person) { $em->remove($place); $em->flush(); } } /** * @Rest\Put( * path = "/person/{id}/update", * name = "update_person" * ) * @Rest\View(StatusCode = Response::HTTP_CREATED) */ public function updatePersonAction(Request $request) { $em = $this->getDoctrine()->getManager(); $person = $em->getRepository('App:Person')->find($request->get('id')); if (empty($place)) { return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND); } $person->setFirstName($request->get('firstname')); $person->setLastName($request->get('lastname')); $person->setEmail($request->get('email')); $em->merge($person); $em->flush(); return $this->view($person, Response::HTTP_CREATED, ['Location' => $this->generateUrl('show_person', ['id' => $person->getId(), UrlGeneratorInterface::ABSOLUTE_URL])]); } /** * @Rest\Get("/person/{id}/friends/localisation") */ public function getFriendsLocalisationAction(Request $request) { } /** * @Rest\Post("/person/{id}/localisation") */ public function updateLocalisationAction(Request $request) { $localisation = new Localisation(); $localisation->setPerson($request->get('id')); $localisation->setTimestamp($request->get('timestamp')); $localisation->setLatitude($request->get('latitude')); $localisation->setLongitude($request->get('longitude')); $em = $this->getDoctrine()->getManager(); $em->persist($localisation); $em->flush(); } /** * @Rest\Get( * path = "/person/{id}", * name = "show_person", * requirements = {"id"="\d+"} * ) * @Rest\View */ public function showPerson(Person $person) { return $person; } /** * @Rest\Get( * path = "/person/{email}", * name = "show_person_by_email", * requirements = {"email"="\s+"} * ) * @Rest\View */ public function showPersonByEmail(Person $person) { return $person; } /** * @Rest\Get( * path = "/person/{id}/friends", * name = "show_person_friends", * requirements = {"id"="\d+"} * ) * @Rest\View */ public function showPersonFriends(Person $person) { return $person->getFriends(); } /** * @Rest\Get( * path = "/person/{email}/friends", * name = "show_person_friends_by_email", * requirements = {"email"="\s+"} * ) * @Rest\View */ public function showPersonFriendsByEmail(Person $person) { return $person->getFriends(); } }