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