Commit 425811c2 authored by Mat's avatar Mat

c'est mieux de gérer la route delete sans le try..catch

parent 4519273f
......@@ -23,6 +23,7 @@ $(document).ready(function()
{
let targetedId;
// supprime une brasserie
$('#delete').click(function(e)
{
e.preventDefault();
......@@ -30,14 +31,12 @@ $(document).ready(function()
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie/" + targetedId,
dataType: 'JSON',
method: 'DELETE',
success: function(data) {
if (data) {
alert('success');
$("li[data-target="+ targetedId +"]").remove();
targetedId = undefined;
} else {
alert('error');
}
success: function(data)
{
alert('success');
$("li[data-target="+ data.id +"]").remove();
targetedId = undefined;
},
error: (xhr) => {
console.log(xhr);
......
......@@ -99,26 +99,16 @@ class BrasserieController extends FOSRestController
}
/**
* @param $id
* @Rest\Delete(path="/brasserie/{id}")
* @param Brasserie $brasserieId
* @Rest\Delete(path="/brasserie/{brasserieId}")
* @Rest\View()
* @return bool
* @return Brasserie
*/
public function deleteAction($id)
public function deleteAction(Brasserie $brasserieId)
{
try {
$brasserie = $this->getDoctrine()
->getRepository(Brasserie::class)
->find($id);
$em = $this->getDoctrine()->getManager();
$em->remove($brasserie);
$em->flush();
return true;
}
catch(\Exception $exception)
{
return false;
}
$em = $this->getDoctrine()->getManager();
$em->remove($brasserieId);
$em->flush();
return $brasserieId;
}
}
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