From 00b332b8ce2c8ba918b4fe570da5e9a107c302a8 Mon Sep 17 00:00:00 2001
From: user <user@imta.fr>
Date: Tue, 25 Mar 2025 23:45:04 +0100
Subject: [PATCH] correction owner wishlist

---
 src/Controller/HomeController.php     |  2 ++
 src/Controller/WishlistController.php |  4 ++--
 src/Entity/User.php                   |  2 +-
 src/Entity/Wishlist.php               | 15 +++++++++++++++
 templates/wishlist/index.html.twig    |  2 +-
 5 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php
index 6a27413e..8967bd5f 100644
--- a/src/Controller/HomeController.php
+++ b/src/Controller/HomeController.php
@@ -17,6 +17,8 @@ class HomeController extends AbstractController
                 'Login' => $this->generateUrl('login'),
                 'My Wishlists' => $this->generateUrl('app_wishlist_index'),
                 'Admin Dashboard' => $this->generateUrl('admin_dashboard'),
+                'Profile' => $this->generateUrl('user_profile'),
+
                         ],
         ]);
     }
diff --git a/src/Controller/WishlistController.php b/src/Controller/WishlistController.php
index 7e1d571a..611eeccd 100644
--- a/src/Controller/WishlistController.php
+++ b/src/Controller/WishlistController.php
@@ -21,7 +21,7 @@ final class WishlistController extends AbstractController
 
 
         return $this->render('wishlist/index.html.twig', [
-            'wishlists' => $user->getWishlists()->toArray()
+            'wishlists' => $user->getWishlists()
         ]);
     }
 
@@ -40,7 +40,7 @@ final class WishlistController extends AbstractController
         }
 
         return $this->render('wishlist/new.html.twig', [
-            'wishlist' => $wishlist,
+            'wishlists' => $wishlist,
             'form' => $form,
         ]); 
         
diff --git a/src/Entity/User.php b/src/Entity/User.php
index 3b99380d..406c8d52 100644
--- a/src/Entity/User.php
+++ b/src/Entity/User.php
@@ -164,7 +164,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
         return $this->wishlists;
     }
 
-    public function addToAuthorWhishlists(Wishlists $wishlist){
+    public function addToAuthorWhishlists(Wishlist $wishlist){
         if (!$this->wishlists->contains($wishlist)) {
             $this->wishlists[] = $wishlist;
         }       
diff --git a/src/Entity/Wishlist.php b/src/Entity/Wishlist.php
index 9c16360e..60d02f6b 100644
--- a/src/Entity/Wishlist.php
+++ b/src/Entity/Wishlist.php
@@ -32,6 +32,21 @@ class Wishlist
     #[ORM\OneToMany(targetEntity: Item::class, mappedBy: 'wishlist', orphanRemoval: true)]
     private Collection $items;
 
+    #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'wishlists')]
+    #[ORM\JoinColumn(nullable: false)]
+    private ?User $owner = null;
+
+    public function getOwner(): ?User
+    {
+        return $this->owner;
+    }
+
+    public function setOwner(?User $owner): static
+    {
+        $this->owner = $owner;
+        return $this;
+    }
+
     public function __construct()
     {
         $this->items = new ArrayCollection();
diff --git a/templates/wishlist/index.html.twig b/templates/wishlist/index.html.twig
index 3f6757e1..f08571c4 100644
--- a/templates/wishlist/index.html.twig
+++ b/templates/wishlist/index.html.twig
@@ -31,6 +31,6 @@
                 <button title="Delete wishlist">🗑</button>
             </div>
         </div>
-        {% end for %}
+        {% endfor %}
     </div>
     {% endblock %}
-- 
GitLab