diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index b593bfa..36a899b 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -32,6 +32,15 @@ class UserController extends AbstractController ]); } + #[Route('/user/{id}', name: 'public_wishlist')] + public function show_user(User $user, WishRepository $wishRepository): Response + { + return $this->render('user/public_wishlist.html.twig', [ + 'username' => $user->getUsername(), + 'wishes' => $wishRepository->findByUser($user), + ]); + } + #[Route('/wishlist', name: 'wishlist')] public function wishlist(Request $request, WishRepository $wishRepository): Response { @@ -47,7 +56,7 @@ class UserController extends AbstractController $this->entityManager->persist($wish); $this->entityManager->flush(); - $this->addFlash("success", "Successfully added the new offering!"); + $this->addFlash("success", "Successfully added the new wish!"); return $this->redirectToRoute('wishlist'); } @@ -58,13 +67,17 @@ class UserController extends AbstractController ]); } - #[Route('/user/{id}', name: 'public_wishlist')] - public function show_user(User $user, WishRepository $wishRepository): Response + #[Route('/wish/delete/{id}', name: 'delete_wish')] + public function deleteWish(Wish $wish): Response { - return $this->render('user/public_wishlist.html.twig', [ - 'username' => $user->getUsername(), - 'wishes' => $wishRepository->findByUser($user), - ]); - } + $user = $this->getUser(); + $user->removeWish($wish); + $this->entityManager->persist($wish); + $this->entityManager->flush(); + + $this->addFlash("success", "Successfully removed the wish!"); + + return $this->redirectToRoute('wishlist'); + } } diff --git a/templates/user/wish.html.twig b/templates/user/wish.html.twig index 6b905dd..0751220 100644 --- a/templates/user/wish.html.twig +++ b/templates/user/wish.html.twig @@ -21,7 +21,11 @@ {% else %} {% endif %} @@ -29,7 +33,7 @@
-
+

New wish

{{ form(wish_form) }}