Commit 9f2abfd6 authored by Mat's avatar Mat

la première route Read de notre API

parent 228abe59
<?php
namespace APIBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
abstract class MasterAPIController extends Controller
{
/**
* @return \Symfony\Component\HttpFoundation\JsonResponse
*
*/
protected function api($data)
{
$serializer = $this->get('jms_serializer');
$serialized = $serializer->serialize($data, 'json');
return new JsonResponse($serialized, 200, array(), true);
}
}
<?php
namespace APIBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
class OwnerController extends MasterAPIController
{
/**
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function readAction()
{
$owners = $this->getDoctrine()->getManager()
->getRepository('TechnoBundle:Owner')->findAllForAPIRead();
return $this->api($owners);
}
/*
$serializer = $this->get('jms_serializer');
$serialized = $serializer->serialize($data, 'json');
return new JsonResponse($serialized, 200, array(), true);
*/
}
api_homepage:
path: /
defaults: { _controller: APIBundle:Default:index }
path: /owners
defaults:
_controller: APIBundle:Owner:read
methods: [ GET ]
......@@ -47,4 +47,17 @@ class OwnerRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @return Owner[]
*/
public function findAllForAPIRead()
{
$qb = $this->createQueryBuilder('o')
->orderBy('o.firstname', 'DESC')
->addOrderBy('o.lastname', 'ASC');
return $qb->getQuery()->getResult();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment