From fc54e21e343230e98b575df144c892c8d1e27b94 Mon Sep 17 00:00:00 2001
From: Julian PEREZ-RAMIREZ <julian.perez-ramirez@imt-atlantique.net>
Date: Fri, 28 Feb 2025 23:06:29 +0100
Subject: [PATCH] adding fields that were missing and updating db scheme

---
 server/README.md                              |  4 +-
 ...25195907.php => Version20250228192241.php} |  6 +-
 .../web_app/src/DataFixtures/ItemFixtures.php |  6 ++
 .../src/DataFixtures/PurchaseFixtures.php     | 55 ++++++++++++++++++-
 .../src/DataFixtures/WishListFixtures.php     | 12 ++++
 server/web_app/src/Entity/Item.php            | 15 +++++
 server/web_app/src/Entity/Purchase.php        | 18 +++---
 server/web_app/src/Entity/WishList.php        | 38 +++++++++++++
 8 files changed, 137 insertions(+), 17 deletions(-)
 rename server/web_app/migrations/{Version20250225195907.php => Version20250228192241.php} (87%)

diff --git a/server/README.md b/server/README.md
index 6220432..f5271fa 100644
--- a/server/README.md
+++ b/server/README.md
@@ -27,12 +27,12 @@ docker exec -it symfony_app php bin/console doctrine:migrations:migrate
 
 Rollback to the previous migrate version
 ```
-php bin/console doctrine:migrations:migrate prev
+docker exec -it symfony_app php bin/console doctrine:migrations:migrate prev
 ```
 
 To add sample data per dafault to the database (after finished editing DataFixtures/ files)
 Note: Add the `--append` flag if you don't want to erase the records already created.
 Also add `--group` to apply and specific file.
 ```
-php bin/console doctrine:fixtures:load
+docker exec -it symfony_app php bin/console doctrine:fixtures:load
 ```
\ No newline at end of file
diff --git a/server/web_app/migrations/Version20250225195907.php b/server/web_app/migrations/Version20250228192241.php
similarity index 87%
rename from server/web_app/migrations/Version20250225195907.php
rename to server/web_app/migrations/Version20250228192241.php
index 967136e..76fcf0a 100644
--- a/server/web_app/migrations/Version20250225195907.php
+++ b/server/web_app/migrations/Version20250228192241.php
@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
 /**
  * Auto-generated Migration: Please modify to your needs!
  */
-final class Version20250225195907 extends AbstractMigration
+final class Version20250228192241 extends AbstractMigration
 {
     public function getDescription(): string
     {
@@ -20,10 +20,10 @@ final class Version20250225195907 extends AbstractMigration
     public function up(Schema $schema): void
     {
         // this up() migration is auto-generated, please modify it to your needs
-        $this->addSql('CREATE TABLE item (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, price DOUBLE PRECISION NOT NULL, purchase_url VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
+        $this->addSql('CREATE TABLE item (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, price DOUBLE PRECISION NOT NULL, purchase_url VARCHAR(255) DEFAULT NULL, is_bought TINYINT(1) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
         $this->addSql('CREATE TABLE purchase (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, wish_list_id INT NOT NULL, item_id INT NOT NULL, url_proof VARCHAR(255) DEFAULT NULL, message VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_6117D13BA76ED395 (user_id), INDEX IDX_6117D13BD69F3311 (wish_list_id), INDEX IDX_6117D13B126F525E (item_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
         $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, user_name VARCHAR(255) DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, surname VARCHAR(255) DEFAULT NULL, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, is_blocked TINYINT(1) DEFAULT NULL, role VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
-        $this->addSql('CREATE TABLE wish_list (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, name VARCHAR(255) NOT NULL, expiration_date DATETIME DEFAULT NULL, is_active TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_5B8739BDA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
+        $this->addSql('CREATE TABLE wish_list (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, expiration_date DATETIME DEFAULT NULL, is_active TINYINT(1) NOT NULL, url_view_mode VARCHAR(255) NOT NULL, url_edit_mode VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_5B8739BDA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
         $this->addSql('CREATE TABLE wishlist_item (wish_list_id INT NOT NULL, item_id INT NOT NULL, INDEX IDX_6424F4E8D69F3311 (wish_list_id), INDEX IDX_6424F4E8126F525E (item_id), PRIMARY KEY(wish_list_id, item_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
         $this->addSql('CREATE TABLE wish_list_member (id INT AUTO_INCREMENT NOT NULL, wish_list_id INT NOT NULL, user_id INT NOT NULL, can_edit TINYINT(1) NOT NULL, is_accepted TINYINT(1) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_F4CA81DFD69F3311 (wish_list_id), INDEX IDX_F4CA81DFA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
         $this->addSql('ALTER TABLE purchase ADD CONSTRAINT FK_6117D13BA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
diff --git a/server/web_app/src/DataFixtures/ItemFixtures.php b/server/web_app/src/DataFixtures/ItemFixtures.php
index a8dcc0c..a422b15 100644
--- a/server/web_app/src/DataFixtures/ItemFixtures.php
+++ b/server/web_app/src/DataFixtures/ItemFixtures.php
@@ -15,30 +15,35 @@ class ItemFixtures extends Fixture
                 'title' => 'Smartphone',
                 'description' => 'Latest model with high-end specs',
                 'price' => 799.99,
+                'is_bought' => true,
                 'purchase_url' => 'https://example.com/smartphone',
             ],
             [
                 'title' => 'Laptop',
                 'description' => 'Powerful laptop for work and gaming',
                 'price' => 1299.49,
+                'is_bought' => true,
                 'purchase_url' => 'https://example.com/laptop',
             ],
             [
                 'title' => 'Wireless Headphones',
                 'description' => 'Noise-canceling headphones with long battery life',
                 'price' => 199.99,
+                'is_bought' => false,
                 'purchase_url' => 'https://example.com/headphones',
             ],
             [
                 'title' => 'Coffee Maker',
                 'description' => 'Automatic coffee maker with multiple settings',
                 'price' => 89.99,
+                'is_bought' => false,
                 'purchase_url' => 'https://example.com/coffee-maker',
             ],
             [
                 'title' => 'Gaming Chair',
                 'description' => 'Ergonomic chair for long gaming sessions',
                 'price' => 249.99,
+                'is_bought' => false,
                 'purchase_url' => 'https://example.com/gaming-chair',
             ]
         ];
@@ -48,6 +53,7 @@ class ItemFixtures extends Fixture
             $item->setTitle($itemData['title']);
             $item->setDescription($itemData['description']);
             $item->setPrice($itemData['price']);
+            $item->setIsBought($itemData['is_bought']);
             $item->setPurchaseUrl($itemData['purchase_url']);
             $item->setCreatedAt(new \DateTimeImmutable());
 
diff --git a/server/web_app/src/DataFixtures/PurchaseFixtures.php b/server/web_app/src/DataFixtures/PurchaseFixtures.php
index 9b6140a..045637e 100644
--- a/server/web_app/src/DataFixtures/PurchaseFixtures.php
+++ b/server/web_app/src/DataFixtures/PurchaseFixtures.php
@@ -2,16 +2,65 @@
 
 namespace App\DataFixtures;
 
+use App\Entity\Purchase;
+use App\Entity\User;
+use App\Entity\WishList;
+use App\Entity\Item;
 use Doctrine\Bundle\FixturesBundle\Fixture;
 use Doctrine\Persistence\ObjectManager;
+use Doctrine\Common\DataFixtures\DependentFixtureInterface;
 
-class PurchaseFixtures extends Fixture
+class PurchaseFixtures extends Fixture implements DependentFixtureInterface
 {
     public function load(ObjectManager $manager): void
     {
-        // $product = new Product();
-        // $manager->persist($product);
+        // Fetch existing users, wishlists, and items from the database
+        $users = $manager->getRepository(User::class)->findAll();
+        $wishLists = $manager->getRepository(WishList::class)->findAll();
+        $items = $manager->getRepository(Item::class)->findAll();
+
+        if (empty($users) || empty($wishLists) || empty($items)) {
+            throw new \Exception('Ensure users, wishlists, and items exist in the database before running this fixture.');
+        }
+
+        $purchasesData = [
+            [
+                'user' => $users[0],
+                'wishList' => $wishLists[0],
+                'item' => $items[0],
+                'url_proof' => 'https://example.com/proof1.jpg',
+                'message' => 'Hope you like this gift!',
+            ],
+            [
+                'user' => $users[1],
+                'wishList' => $wishLists[0],
+                'item' => $items[1],
+                'url_proof' => 'https://example.com/proof2.jpg',
+                'message' => 'A little surprise for you!',
+            ]
+        ];
+
+        foreach ($purchasesData as $data) {
+            $purchase = new Purchase();
+            $purchase->setUser($data['user']);
+            $purchase->setWishList($data['wishList']);
+            $purchase->setItem($data['item']);
+            $purchase->setUrlProof($data['url_proof']);
+            $purchase->setMessage($data['message']);
+            $purchase->setCreatedAt(new \DateTimeImmutable());
+
+            $manager->persist($purchase);
+        }
 
         $manager->flush();
     }
+
+    public function getDependencies(): array
+    {
+        return [
+            UserFixtures::class,
+            WishListFixtures::class,
+            ItemFixtures::class,
+        ];
+    }
 }
diff --git a/server/web_app/src/DataFixtures/WishListFixtures.php b/server/web_app/src/DataFixtures/WishListFixtures.php
index cd735e6..eef728f 100644
--- a/server/web_app/src/DataFixtures/WishListFixtures.php
+++ b/server/web_app/src/DataFixtures/WishListFixtures.php
@@ -25,33 +25,45 @@ class WishListFixtures extends Fixture implements DependentFixtureInterface
         $wishListsData = [
             [
                 'name' => 'John\'s Birthday Wishlist',
+                'description' => 'Birthday Wishlist',
                 'user' => $users[0],  // Assuming at least one user exists
                 'items' => [$items[0], $items[1]],  // Adding first two items
                 'expiration_date' => new \DateTime('+30 days'),
                 'is_active' => true,
+                'url_view_mode' => 'http:://url_view_mode.com',
+                'url_edit_mode' => 'http:://url_edit_mode.com',
             ],
             [
                 'name' => 'Tech Gadgets Wishlist',
+                'description' => 'Gadgets Wishlist',
                 'user' => $users[1],  // Use second user if available, else first user
                 'items' => [$items[2], $items[3], $items[4]],  // Adding three different items
                 'expiration_date' => new \DateTime('+60 days'),
                 'is_active' => true,
+                'url_view_mode' => 'http:://url_view_mode.com',
+                'url_edit_mode' => 'http:://url_edit_mode.com',
             ],
             [
                 'name' => 'Home Essentials Wishlist',
+                'description' => 'Essentials Wishlist',
                 'user' => $users[2],  // Use third user if available, else first user
                 'items' => [$items[1], $items[4]],  // Adding two different items
                 'expiration_date' => new \DateTime('+90 days'),
                 'is_active' => false,
+                'url_view_mode' => 'http:://url_view_mode.com',
+                'url_edit_mode' => 'http:://url_edit_mode.com',
             ],
         ];
 
         foreach ($wishListsData as $wishListData) {
             $wishList = new WishList();
             $wishList->setName($wishListData['name']);
+            $wishList->setDescription($wishListData['description']);
             $wishList->setUser($wishListData['user']);
             $wishList->setExpirationDate($wishListData['expiration_date']);
             $wishList->setIsActive($wishListData['is_active']);
+            $wishList->setUrlViewMode($wishListData['url_view_mode']);
+            $wishList->setUrlEditMode($wishListData['url_edit_mode']);
             $wishList->setCreatedAt(new \DateTimeImmutable());
 
             foreach ($wishListData['items'] as $item) {
diff --git a/server/web_app/src/Entity/Item.php b/server/web_app/src/Entity/Item.php
index 75a011f..5d79fe8 100644
--- a/server/web_app/src/Entity/Item.php
+++ b/server/web_app/src/Entity/Item.php
@@ -25,6 +25,9 @@ class Item
     #[ORM\Column(length: 255, nullable: true)]
     private ?string $purchase_url = null;
 
+    #[ORM\Column(length: 255, nullable: true)]
+    private ?bool $is_bought = null;
+
     #[ORM\Column]
     private ?\DateTimeImmutable $created_at = null;
 
@@ -81,6 +84,18 @@ class Item
         return $this;
     }
 
+    public function isBought(): ?bool
+    {
+        return $this->is_bought;
+    }
+
+    public function setIsBought(?bool $is_bought): static
+    {
+        $this->is_bought = $is_bought;
+
+        return $this;
+    }
+
     public function getCreatedAt(): ?\DateTimeImmutable
     {
         return $this->created_at;
diff --git a/server/web_app/src/Entity/Purchase.php b/server/web_app/src/Entity/Purchase.php
index 7f65dc8..d1c50be 100644
--- a/server/web_app/src/Entity/Purchase.php
+++ b/server/web_app/src/Entity/Purchase.php
@@ -15,15 +15,15 @@ class Purchase
 
     #[ORM\ManyToOne(targetEntity: User::class)]
     #[ORM\JoinColumn(nullable: false)]
-    private ?int $user = null;
+    private ?User $user = null;
 
     #[ORM\ManyToOne(targetEntity: WishList::class)]
     #[ORM\JoinColumn(nullable: false)]
-    private ?int $wishList = null;
+    private ?WishList $wishList = null;
 
     #[ORM\ManyToOne(targetEntity: Item::class)]
     #[ORM\JoinColumn(nullable: false)]
-    private ?int $item = null;
+    private ?Item $item = null;
 
     #[ORM\Column(length: 255, nullable: true)]
     private ?string $url_proof = null;
@@ -39,36 +39,36 @@ class Purchase
         return $this->id;
     }
 
-    public function getUser(): ?int
+    public function getUser(): ?User
     {
         return $this->user;
     }
 
-    public function setUser(int $user): static
+    public function setUser(User $user): static
     {
         $this->user = $user;
 
         return $this;
     }
 
-    public function getWishList(): ?int
+    public function getWishList(): ?WishList
     {
         return $this->wishlist;
     }
 
-    public function setWishList(int $wishList): static
+    public function setWishList(WishList $wishList): static
     {
         $this->wishList = $wishList;
 
         return $this;
     }
 
-    public function getItem(): ?int
+    public function getItem(): ?Item
     {
         return $this->item;
     }
 
-    public function setItem(int $item): static
+    public function setItem(Item $item): static
     {
         $this->item = $item;
 
diff --git a/server/web_app/src/Entity/WishList.php b/server/web_app/src/Entity/WishList.php
index cb593dc..b4ced59 100644
--- a/server/web_app/src/Entity/WishList.php
+++ b/server/web_app/src/Entity/WishList.php
@@ -23,6 +23,9 @@ class WishList
     #[ORM\Column(length: 255)]
     private ?string $name = null;
 
+    #[ORM\Column(length: 255)]
+    private ?string $description = null;
+
     #[ORM\ManyToMany(targetEntity: Item::class)]
     #[ORM\JoinTable(name: "wishlist_item")]
     private Collection $items;
@@ -33,6 +36,13 @@ class WishList
     #[ORM\Column]
     private ?bool $is_active = null;
 
+    //add getters and setters 
+    #[ORM\Column(length: 255)]
+    private ?string $urlViewMode = null;
+
+    #[ORM\Column(length: 255)]
+    private ?string $urlEditMode = null;
+
     #[ORM\Column]
     private ?\DateTimeImmutable $created_at = null;
 
@@ -70,6 +80,18 @@ class WishList
         return $this;
     }
 
+    public function getDescription(): ?string
+    {
+        return $this->name;
+    }
+
+    public function setDescription(string $description): static
+    {
+        $this->description = $description;
+
+        return $this;
+    }
+
     public function getExpirationDate(): ?\DateTimeInterface
     {
         return $this->expiration_date;
@@ -94,6 +116,22 @@ class WishList
         return $this;
     }
 
+    public function getUrlViewMode () {
+        return $this->urlViewMode;
+    }
+
+    public function setUrlViewMode (string $urlViewMode) {
+        $this->urlViewMode = $urlViewMode;
+    }
+
+    public function getUrlEditMode () {
+        return $this->urlViewMode;
+    }
+
+    public function setUrlEditMode (string $urlEditMode) {
+        $this->urlEditMode = $urlEditMode;
+    }
+
     public function getCreatedAt(): ?\DateTimeImmutable
     {
         return $this->created_at;
-- 
GitLab