{
/**
* @Rest\Post(
- * path = "/api/person/inscription",
+ * path = "/person/inscription",
* name = "create_person"
* )
* @Rest\View(StatusCode = Response::HTTP_CREATED)
$em->persist($person);
$em->flush();
- //TODO: use ViewHandler
return $this->view($person, Response::HTTP_CREATED, ['Location' => $this->generateUrl('show_person', ['id' => $person->getId(), UrlGeneratorInterface::ABSOLUTE_URL])]);
}
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('App:Person')->find($request->get('id'));
- $viewHandler = $this->get('fos_rest.view_handler');
-
if (empty($person)) {
- return $this->PersonNotFound($viewHandler);
+ return $this->PersonNotFound();
}
$person->setFirstName($request->get('firstname'));
$em->merge($person);
$em->flush();
- //TODO: use ViewHandler
return $this->view($person, Response::HTTP_CREATED, ['Location' => $this->generateUrl('show_person', ['id' => $person->getId(), UrlGeneratorInterface::ABSOLUTE_URL])]);
}
$em = $this->getDoctrine()->getManager();
$localisations = $em->getRepository('App:Localisation')->findBy(['person' => $request->get('id')]);
- $viewHandler = $this->get('fos_rest.view_handler');
-
if (empty($localisations)) {
- return $this->PersonLocalisationsNotFound($viewHandler);
+ return $this->PersonLocalisationsNotFound();
}
- $view = View::create($localisations);
- $view->setFormat('json');
-
- return $viewHandler->handle($view);
-
+ return $localisations;
}
/**
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('App:Person')->find($request->get('id'));
- $viewHandler = $this->get('fos_rest.view_handler');
-
if (empty($person)) {
- return $this->PersonNotFound($viewHandler);
+ return $this->PersonNotFound();
}
- $view = View::create($person);
- $view->setFormat('json');
-
- return $viewHandler->handle($view);
+ return $person;
}
/**
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('App:Person')->findOneBy(['email' => $request->get('email')]);
- $viewHandler = $this->get('fos_rest.view_handler');
-
if (empty($person)) {
- return $this->PersonNotFound($viewHandler);
+ return $this->PersonNotFound();
}
- $view = View::create($person);
- $view->setFormat('json');
-
- return $viewHandler->handle($view);
+ return $person;
}
/**
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('App:Person')->find($request->get('id'));
- $viewHandler = $this->get('fos_rest.view_handler');
-
if (empty($person)) {
- return $this->PersonNotFound($viewHandler);
+ return $this->PersonNotFound();
}
- $view = View::create($person->getFriends());
- $view->setFormat('json');
-
- return $viewHandler->handle($view);
+ return $person->getFriends();
}
/**
$em = $this->getDoctrine()->getManager();
$persons = $em->getRepository('App:Person')->findAll();
- $viewHandler = $this->get('fos_rest.view_handler');
-
if (empty($persons)) {
- return $this->PersonNotFound($viewHandler);
+ return $this->PersonNotFound();
}
- // $view = View::create($persons);
- // $view->setFormat('json');
- //
- // return $viewHandler->handle($view);
return $persons;
}
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('App:Person')->findOneBy(['email' => $request->get('email')]);
- $viewHandler = $this->get('fos_rest.view_handler');
-
if (empty($person)) {
- return $this->PersonNotFound($viewHandler);
+ return $this->PersonNotFound();
}
- $view = View::create($person->getFriends());
- $view->setFormat('json');
-
- return $viewHandler->handle($view);
+ return $person->getFriends();
}
- private function PersonNotFound($viewHandler) {
- return $viewHandler->handle(View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND));
+ private function PersonNotFound() {
+ return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
}
- private function PersonLocalisationsNotFound($viewHandler) {
- return $viewHandler->handle(View::create(['message' => 'Person localisations not found'], Response::HTTP_NOT_FOUND));
+ private function PersonLocalisationsNotFound() {
+ return View::create(['message' => 'Person localisations not found'], Response::HTTP_NOT_FOUND);
}
}