From 07cb90e7fb9791ba92fd9e4355b2a93cd571ea99 Mon Sep 17 00:00:00 2001 From: Jannis Portmann Date: Sat, 15 May 2021 12:18:23 +0200 Subject: [PATCH] implement deletion of offer --- src/Controller/OfferController.php | 18 ++++++++++++++++++ templates/app/offer.html.twig | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Controller/OfferController.php b/src/Controller/OfferController.php index 1c1f01d..49d260a 100644 --- a/src/Controller/OfferController.php +++ b/src/Controller/OfferController.php @@ -120,4 +120,22 @@ class OfferController extends AbstractController throw new HttpException(403, "No permission"); } + + #[Route('/offer/delete/{id}', name: 'delete_offer')] + public function deleteOffer(Offering $offer): Response + { + $user = $this->getUser(); + + if ($offer->getByUser() === $user) + { + $this->entityManager->remove($offer); + $this->entityManager->flush(); + } + + $this->addFlash( + 'success','Successfully removed offer!' + ); + + return $this->redirectToRoute('user_page'); + } } diff --git a/templates/app/offer.html.twig b/templates/app/offer.html.twig index 971bc38..8c9af9f 100644 --- a/templates/app/offer.html.twig +++ b/templates/app/offer.html.twig @@ -21,7 +21,7 @@ {% if offer.byUser == user %} - + {% else %}

Wishes

{{ offer.byUser }} would like some of the following in return: