From ea86bfbea3561f685251941f2d54056058e365bd Mon Sep 17 00:00:00 2001
From: Julian PEREZ-RAMIREZ <julian.perez-ramirez@imt-atlantique.net>
Date: Sun, 23 Feb 2025 16:28:10 +0100
Subject: [PATCH] adding relationships between tables

---
 web_app/src/Entity/Purchase.php       |  6 ++++++
 web_app/src/Entity/User.php           |  2 +-
 web_app/src/Entity/WishList.php       |  3 ++-
 web_app/src/Entity/WishListItem.php   |  4 ++++
 web_app/src/Entity/WishListMember.php | 11 +++++++++++
 5 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/web_app/src/Entity/Purchase.php b/web_app/src/Entity/Purchase.php
index 14a31b9..e165081 100644
--- a/web_app/src/Entity/Purchase.php
+++ b/web_app/src/Entity/Purchase.php
@@ -14,12 +14,18 @@ class Purchase
     private ?int $id = null;
 
     #[ORM\Column]
+    #[ORM\ManyToOne(targetEntity: User::class)]
+    #[ORM\JoinColumn(nullable: false)]
     private ?int $user_id = null;
 
     #[ORM\Column]
+    #[ORM\ManyToOne(targetEntity: Wishlist::class)]
+    #[ORM\JoinColumn(nullable: false)]
     private ?int $wishlist_id = null;
 
     #[ORM\Column]
+    #[ORM\ManyToOne(targetEntity: Item::class)]
+    #[ORM\JoinColumn(nullable: false)]
     private ?int $item_id = null;
 
     #[ORM\Column(length: 255, nullable: true)]
diff --git a/web_app/src/Entity/User.php b/web_app/src/Entity/User.php
index f3427be..3c6a72d 100644
--- a/web_app/src/Entity/User.php
+++ b/web_app/src/Entity/User.php
@@ -23,7 +23,7 @@ class User
     #[ORM\Column(length: 255, nullable: true)]
     private ?string $surname = null;
 
-    #[ORM\Column(length: 255)]
+    #[ORM\Column(length: 255, unique: true)]
     private ?string $email = null;
 
     #[ORM\Column(length: 255)]
diff --git a/web_app/src/Entity/WishList.php b/web_app/src/Entity/WishList.php
index 3ed0aa8..acbb88b 100644
--- a/web_app/src/Entity/WishList.php
+++ b/web_app/src/Entity/WishList.php
@@ -14,7 +14,8 @@ class WishList
     #[ORM\Column]
     private ?int $id = null;
 
-    #[ORM\Column]
+    #[ORM\ManyToOne(targetEntity: User::class)]
+    #[ORM\JoinColumn(nullable: false)]
     private ?int $user_id = null;
 
     #[ORM\Column(length: 255)]
diff --git a/web_app/src/Entity/WishListItem.php b/web_app/src/Entity/WishListItem.php
index e83f9d9..93fb8c6 100644
--- a/web_app/src/Entity/WishListItem.php
+++ b/web_app/src/Entity/WishListItem.php
@@ -14,9 +14,13 @@ class WishListItem
     private ?int $id = null;
 
     #[ORM\Column]
+    #[ORM\ManyToOne(targetEntity: Wishlist::class)]
+    #[ORM\JoinColumn(nullable: false)]
     private ?int $wishlist_id = null;
 
     #[ORM\Column]
+    #[ORM\ManyToOne(targetEntity: Item::class)]
+    #[ORM\JoinColumn(nullable: false)]
     private ?int $item_id = null;
 
     public function getId(): ?int
diff --git a/web_app/src/Entity/WishListMember.php b/web_app/src/Entity/WishListMember.php
index ee4e53f..ab749cc 100644
--- a/web_app/src/Entity/WishListMember.php
+++ b/web_app/src/Entity/WishListMember.php
@@ -14,9 +14,13 @@ class WishListMember
     private ?int $id = null;
 
     #[ORM\Column]
+    #[ORM\ManyToOne(targetEntity: Wishlist::class)]
+    #[ORM\JoinColumn(nullable: false)]
     private ?int $wishlist_id = null;
 
     #[ORM\Column]
+    #[ORM\ManyToOne(targetEntity: User::class)]
+    #[ORM\JoinColumn(nullable: false)]
     private ?int $user_id = null;
 
     #[ORM\Column]
@@ -92,4 +96,11 @@ class WishListMember
 
         return $this;
     }
+
+    public function setId(?Wishlist $id): static
+    {
+        $this->id = $id;
+
+        return $this;
+    }
 }
-- 
GitLab