From 65413ef8ce8ca9a2f6034cd47d7551c3df602e2d Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 17 Jul 2024 22:42:56 +0200 Subject: [PATCH] add fixtures, add price to Product --- .idea/workspace.xml | 9 ++------ migrations/Version20240717204253.php | 31 ++++++++++++++++++++++++++++ src/DataFixtures/AppFixtures.php | 23 ++++++++++++++++----- src/Entity/Product.php | 15 ++++++++++++++ src/Entity/ProductSold.php | 3 +++ 5 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 migrations/Version20240717204253.php diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5745cc4d..4cac70c2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -24,14 +24,9 @@ - - + - - - - diff --git a/migrations/Version20240717204253.php b/migrations/Version20240717204253.php new file mode 100644 index 00000000..baaa71b5 --- /dev/null +++ b/migrations/Version20240717204253.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE product ADD price INT NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE product DROP price'); + } +} diff --git a/src/DataFixtures/AppFixtures.php b/src/DataFixtures/AppFixtures.php index 7d3ce87b..6e73ff75 100644 --- a/src/DataFixtures/AppFixtures.php +++ b/src/DataFixtures/AppFixtures.php @@ -13,10 +13,22 @@ class AppFixtures extends Fixture $expense = new Exepense(); $expense->setName('courses au marché') ->setAmount(40); + $expense2 = new Exepense(); + $expense2->setName('abonnement service compta') + ->setAmount(60); + $expense3 = new Exepense(); + $expense3->setName('plutonium récréatif') + ->setAmount(15); $product = new Product(); $product->setName('Un Livre d\'exemple'); + $product2 = new Product(); + $product2->setName('Un poster') + ->setPrice(12); + $product3 = new Product(); + $product3->setName('Chaudière à sel fondus')->setPrice(120000000); + $categ = new Category(); $categ->setName('Livres'); @@ -26,11 +38,12 @@ class AppFixtures extends Fixture ->setEmail('demo@demo.com') ->setRoles('ROLE_ADMIN') ->addExpenseConfig($expense) - ->addProduct($product); - - $product - ->setCategory($categ) - ->setOwner($demo_user); + ->addExpenseConfig($expense2) + ->addExpenseConfig($expense3) + ->addProduct($product) + ->addProduct($product2) + ->addProduct($product3) + ; $expense->setOwner($demo_user); diff --git a/src/Entity/Product.php b/src/Entity/Product.php index e687743a..66a9ac54 100644 --- a/src/Entity/Product.php +++ b/src/Entity/Product.php @@ -30,6 +30,9 @@ class Product #[ORM\ManyToOne(inversedBy: 'products')] private ?ProductCategory $productCategory = null; + #[ORM\Column] + private ?int $price = null; + public function getId(): ?int { return $this->id; @@ -94,4 +97,16 @@ class Product return $this; } + + public function getPrice(): ?int + { + return $this->price; + } + + public function setPrice(int $price): static + { + $this->price = $price; + + return $this; + } } diff --git a/src/Entity/ProductSold.php b/src/Entity/ProductSold.php index c85af262..ae07a758 100644 --- a/src/Entity/ProductSold.php +++ b/src/Entity/ProductSold.php @@ -8,6 +8,9 @@ use ApiPlatform\Metadata\ApiResource; #[ORM\Entity(repositoryClass: ProductSoldRepository::class)] #[ApiResource] +/*** + * Un ensemble de produits vendus + **/ class ProductSold { #[ORM\Id]