Commit 4519273f authored by Mat's avatar Mat

supprimer une brasserie

parent 61037456
......@@ -14,14 +14,37 @@
Nom <input type="text" name="nom"><br>
Adresse <input type="text" name="adresse"><br>
Pays <input type="text" name="pays"><br>
<button id="send">Envoyer</button>
<button id="send">Enregistrer</button>
</form>
<button id="delete">Supprimer</button>
<script>
$(document).ready(function()
{
let targetedId;
$('#delete').click(function(e)
{
e.preventDefault();
$.ajax({
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');
}
},
error: (xhr) => {
console.log(xhr);
}
});
});
// charge le select avec la liste des pays
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/pays/used",
......
......@@ -97,5 +97,28 @@ class BrasserieController extends FOSRestController
->getRepository(Brasserie::class)
->findBy(array('pays' => $paysID));
}
/**
* @param $id
* @Rest\Delete(path="/brasserie/{id}")
* @Rest\View()
* @return bool
*/
public function deleteAction($id)
{
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;
}
}
}
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