implement deletion of wishes
This commit is contained in:
parent
35e9cb1fb9
commit
ffbc8e2c6d
2 changed files with 27 additions and 10 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,11 @@
|
|||
{% else %}
|
||||
<ul class="list-group">
|
||||
{% for wish in wishes %}
|
||||
<li class="list-group-item"> {{ wish.title }}</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center"> {{ wish.title }}
|
||||
<span>
|
||||
<a href="{{ path('delete_wish', {'id': wish.id}) }}"><button class="btn btn-danger">Delete</button></a>
|
||||
</span>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
@ -29,7 +33,7 @@
|
|||
|
||||
<hr>
|
||||
|
||||
<div mb-3>
|
||||
<div class="mb-3">
|
||||
<h3><i class="fas fa-star"></i> New wish</h3>
|
||||
{{ form(wish_form) }}
|
||||
</div>
|
||||
|
|
Reference in a new issue