namespace App\Controller;
use App\Entity\Person;
-use FOS\RestBundle\Controller\FOSRestController;
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+#use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
+use FOS\RestBundle\View\ViewHandler;
+use FOS\RestBundle\View\View;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
-class PersonController extends FOSRestController
+class PersonController extends Controller
{
/**
* @Rest\Post(
public function removePersonAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
- $person = $em->getRepository('App::Person')->find($request->get('id'));
+ $person = $em->getRepository('App:Person')->find($request->get('id'));
if (!empty($person)) {
$em->remove($person);
public function updatePersonAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
- $person = $em->getRepository('App::Person')->find($request->get('id'));
+ $person = $em->getRepository('App:Person')->find($request->get('id'));
if (empty($person)) {
return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
*/
public function showPerson(Request $request)
{
- $em = $this->getDoctrine()->getManager();
- $person = $em->getRepository('App::Person')->find($request->get('id'));
+ $em = $this->getDoctrine()->getManager();
+ $person = $em->getRepository('App:Person')->find($request->get('id'));
- if (empty($person)) {
+ if (empty($person)) {
return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
}
- return $person;
+ $view = View::create($person);
+ $view->setFormat('json');
+
+ return $view;
}
/**
*/
public function showPersonByEmail(Request $request)
{
- $em = $this->getDoctrine()->getManager();
- $person = $em->getRepository('App::Person')->find($request->get('email'));
+ $em = $this->getDoctrine()->getManager();
+ $person = $em->getRepository('App:Person')->find($request->get('email'));
- if (empty($person)) {
- return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
- }
+ if (empty($person)) {
+ return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
+ }
- return $person;
+ $view = View::create($person);
+ $view->setFormat('json');
+
+ return $view;
}
/**
*/
public function showPersonFriends(Request $request)
{
- $em = $this->getDoctrine()->getManager();
- $person = $em->getRepository('App::Person')->find($request->get('id'));
+ $em = $this->getDoctrine()->getManager();
+ $person = $em->getRepository('App:Person')->find($request->get('id'));
- if (empty($person)) {
- return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
- }
+ if (empty($person)) {
+ return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
+ }
- return $person->getFriends();
+ $view = View::create($person->getFriends());
+ $view->setFormat('json');
+
+ return $view;
}
/**
*/
public function showPersonFriendsByEmail(Request $request)
{
- $em = $this->getDoctrine()->getManager();
- $person = $em->getRepository('App::Person')->find($request->get('email'));
+ $em = $this->getDoctrine()->getManager();
+ $person = $em->getRepository('App:Person')->find($request->get('email'));
+
+ if (empty($person)) {
+ return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
+ }
- if (empty($person)) {
- return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
- }
+ $view = View::create($person->getFriends());
+ $view->setFormat('json');
- return $person->getFriends();
+ return $view;
}
}