Commit afd5bb4f authored by Mat's avatar Mat

complète le CRUD Info

parent 167c2c86
......@@ -44,17 +44,66 @@ class InfoAPIController extends MasterAPIController
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function readOneAction($id)
{
$em = $this->getDoctrine()->getManager();
$info = $em->getRepository('PotageBundle:Info')->findOneForAPIRead($id);
if ($info === null) {
return $this->api('Not found', Response::HTTP_NOT_FOUND);
}
return $this->api($info);
}
/**
* @param Request $request
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$info = $em->getRepository('PotageBundle:Info')->findOneForAPIUpdate($id);
if ($info === null) {
return $this->api('Not found', Response::HTTP_NOT_FOUND);
}
$form = $this->createForm(InfoAPIType::class, $info);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em->flush();
return $this->api($info);
}
return $this->api($form, Response::HTTP_BAD_REQUEST);
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function deleteAction($id)
{
$em = $this->getDoctrine()->getManager();
$info = $em->getRepository('PotageBundle:Info')->findOneForAPIDelete($id);
if ($info !== null)
{
$em->remove($info);
$em->flush();
}
return $this->api([]);
}
}
......@@ -201,6 +201,30 @@ api_info_create:
_controller: APIBundle:InfoAPI:create
methods: [ POST ]
api_info_read_one:
path: /info/{id}
requirements:
id: \d+
defaults:
_controller: APIBundle:InfoAPI:readOne
methods: [ GET ]
api_info_update:
path: /info/{id}
requirements:
id: \d+
defaults:
_controller: APIBundle:InfoAPI:update
methods: [ POST ]
api_info_delete:
path: /info/{id}
requirements:
id: \d+
defaults:
_controller: APIBundle:InfoAPI:delete
methods: [ DELETE ]
## CRUD GroupeAPI
......
......@@ -20,6 +20,46 @@ class InfoRepository extends \Doctrine\ORM\EntityRepository
->orderBy('i.id', 'DESC');
return $qb->getQuery()->getResult();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForAPIRead($id)
{
$qb = $this->createQueryBuilder('i')
->where('i.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForAPIUpdate($id)
{
$qb = $this->createQueryBuilder('i')
->where('i.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForAPIDelete($id)
{
$qb = $this->createQueryBuilder('i')
->where('i.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