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