- * @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();
- }
+ * @Rest\Get(
+ * path = "/api/person/{id}",
+ * name = "show_person",
+ * requirements = {"id"="\d+"}
+ * )
+ * @Rest\View()
+ */
+ public function showPerson(Request $request)
+ {
+ $em = $this->getDoctrine()->getManager();
+ $person = $em->getRepository('App:Person')->find($request->get('id'));
+
+ if (empty($person)) {
+ return $this->PersonNotFound();
+ }
+
+ return $person;
+ }
+
+ /**
+ * @Rest\Get(
+ * path = "/api/person/{id}/friends",
+ * name = "show_person_friends",
+ * requirements = {"id"="\d+"}
+ * )
+ * @Rest\View()
+ */
+ public function showPersonFriends(Request $request)
+ {
+ $em = $this->getDoctrine()->getManager();
+ $person = $em->getRepository('App:Person')->find($request->get('id'));
+
+ if (empty($person)) {
+ return $this->PersonNotFound();
+ }
+
+ return $person->getFriends();
+ }
+
+ /**
+ * @Rest\Get(
+ * path = "/api/persons",
+ * name = "show_persons"
+ * )
+ * @Rest\View()
+ */
+ public function showPersons(Request $request)
+ {
+ $em = $this->getDoctrine()->getManager();
+ $persons = $em->getRepository('App:Person')->findAll();
+
+ if (empty($persons)) {
+ return $this->PersonsNotFound();
+ }
+
+ return $persons;
+ }
+
+ private function PersonNotFound() {
+ 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);
+ }
+