diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index fef96537d168fa9c22c83f939f7e22f3df50e227..1df2e142c75372f9f8dd279262021817e66b1e4a 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -6,7 +6,7 @@ services: container_name: db_docker_symfony restart: always volumes: - - ./server/mysql_data:/var/lib/mysql #this line maps the content of ./server/mysql_data in your pc to the /var/lib/mysql of the container + - ./server/mysql_data:/var/lib/mysql ports: - 3306:3306 environment: diff --git a/src/Controller/WishlistController.php b/src/Controller/WishlistController.php index 84db524a67d2d0373d124b07acbe8eb321ece233..bc5046206b7d498c9e7002bd9c2a3e0afa8de6e6 100644 --- a/src/Controller/WishlistController.php +++ b/src/Controller/WishlistController.php @@ -47,6 +47,8 @@ final class WishlistController extends AbstractController ]); } + +// Method to display a wishlist items #[Route('/{id}', name: 'app_wishlist_show', methods: ['GET'])] public function show(Wishlist $wishlist, Request $request): Response { @@ -87,7 +89,6 @@ public function show(Wishlist $wishlist, Request $request): Response public function edit(Request $request, Wishlist $wishlist, EntityManagerInterface $entityManager): Response { - $form = $this->createForm(WishlistType::class, $wishlist); $form->handleRequest($request); @@ -105,12 +106,12 @@ public function show(Wishlist $wishlist, Request $request): Response } // Method to delete a wishlist - #[Route('/{id}', name: 'app_wishlist_delete', methods: ['POST'])] + #[Route('/{id}', name: 'app_wishlist_delete', methods: ['DELETE'])] public function delete(Request $request, Wishlist $wishlist, EntityManagerInterface $entityManager): Response { // Validate the CSRF token before deleting the wishlist if ($this->isCsrfTokenValid('delete'.$wishlist->getId(), $request->getPayload()->getString('_token'))) { - $entityManager->delete($wishlist); // Remove the wishlist from the database + $entityManager->remove($wishlist); // Remove the wishlist from the database $entityManager->flush(); // Save changes to the database } diff --git a/src/Entity/User.php b/src/Entity/User.php index 8cd12256ad66757e6a357948b61e54e3ce5faacc..5d5149d80ef571f366fc8b91cdb4111b0495b0a5 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -56,7 +56,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(length: 255, nullable: true)] private ?string $image = null; - #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Wishlist::class)] + #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Wishlist::class , cascade: ['remove'])] private Collection $wishlists; // #[ORM\OneToMany(mappedBy: 'invitedUser', targetEntity: Item::class)] diff --git a/src/Entity/Wishlist.php b/src/Entity/Wishlist.php index 871bfe5b7f6ed6a30ea6cef28f0be629af3562f6..b6434e9ea1e19b89ad42e0ca3fe9691540422440 100644 --- a/src/Entity/Wishlist.php +++ b/src/Entity/Wishlist.php @@ -34,8 +34,8 @@ class Wishlist private Collection $items; - #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'wishlists', cascade: ['remove'] )] - #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] + #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'wishlists' )] + #[ORM\JoinColumn(nullable: false)] private ?User $owner = null; public function getOwner(): ?User diff --git a/templates/wishlist/index.html.twig b/templates/wishlist/index.html.twig index cc841372fa2ac7cc22dfc968a2c7da167be42a34..2f584c23e2ff920e261bda52c462556c8c4a75a9 100644 --- a/templates/wishlist/index.html.twig +++ b/templates/wishlist/index.html.twig @@ -59,7 +59,11 @@ <button type="button" class="share-btn" data-wishlist-id="{{ wishlist.id }}">↗</button> <button title="Edit title"><a href="{{ path('app_wishlist_edit', { 'id': wishlist.id }) }}">✏</a></button> - <button title="Delete wishlist"> <a href="{{path('app_wishlist_delete', {'id':wishlist.id} ) }}">🗑</a> </button> + <form action="{{ path('app_wishlist_delete', {'id': wishlist.id}) }}" method="POST" style="display: inline-block"> + <input type="hidden" name="_method" value="DELETE"> + <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ wishlist.id) }}"> + <button type="submit" title="Delete wishlist">🗑</button> + </form> </div> {% endfor %} </div>