Commit f47220c5 authored by Mat's avatar Mat

APIBundle, révision et nouvelle fonction deleteAction() dans le controller

parent e9b381c9
......@@ -12,8 +12,8 @@ class OwnerController extends MasterAPIController
*/
public function readAction()
{
$owners = $this->getDoctrine()->getManager()
->getRepository('TechnoBundle:Owner')->findAllForAPIRead();
$em = $this->getDoctrine()->getManager();
$owners = $em->getRepository('TechnoBundle:Owner')->findAllForAPIRead();
return $this->api($owners);
}
......@@ -28,13 +28,29 @@ class OwnerController extends MasterAPIController
$owner = $em->getRepository('TechnoBundle:Owner')
->findOneForAPIRead($id);
if ($owner === null) {
throw $this->createNotFoundException();
}
return $this->api($owner);
}
/*
$serializer = $this->get('jms_serializer');
$serialized = $serializer->serialize($data, 'json');
return new JsonResponse($serialized, 200, array(), true);
/**
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function deleteOneAction($id)
{
$em = $this->getDoctrine()->getManager();
$owner = $em->getRepository('TechnoBundle:Owner')
->findOneForAPIdelete($id);
if ($owner !== null)
{
$em->remove($owner);
$em->flush();
}
return $this->api([]);
}
}
......@@ -73,4 +73,17 @@ class OwnerRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
* @return Owner
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForAPIdelete($id)
{
$qb = $this->createQueryBuilder('o')
->where('o.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
}
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