feat(produit): Ajoute l'entité Produit, son repository et la migration associée.

This commit is contained in:
Serreau Jovann
2026-01-16 13:44:08 +01:00
parent 93f9a35130
commit 7a43efc9b7
3 changed files with 200 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260116124335 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE product (id SERIAL NOT NULL, ref VARCHAR(255) NOT NULL, category VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, price_day DOUBLE PRECISION NOT NULL, price_sup DOUBLE PRECISION NOT NULL, installation DOUBLE PRECISION NOT NULL, caution DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('DROP TABLE product');
}
}

125
src/Entity/Product.php Normal file
View File

@@ -0,0 +1,125 @@
<?php
namespace App\Entity;
use App\Repository\ProductRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
class Product
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $ref = null;
#[ORM\Column(length: 255)]
private ?string $category = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column]
private ?float $priceDay = null;
#[ORM\Column]
private ?float $priceSup = null;
#[ORM\Column]
private ?float $installation = null;
#[ORM\Column]
private ?float $caution = null;
public function getId(): ?int
{
return $this->id;
}
public function getRef(): ?string
{
return $this->ref;
}
public function setRef(string $ref): static
{
$this->ref = $ref;
return $this;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(string $category): static
{
$this->category = $category;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getPriceDay(): ?float
{
return $this->priceDay;
}
public function setPriceDay(float $priceDay): static
{
$this->priceDay = $priceDay;
return $this;
}
public function getPriceSup(): ?float
{
return $this->priceSup;
}
public function setPriceSup(float $priceSup): static
{
$this->priceSup = $priceSup;
return $this;
}
public function getInstallation(): ?float
{
return $this->installation;
}
public function setInstallation(float $installation): static
{
$this->installation = $installation;
return $this;
}
public function getCaution(): ?float
{
return $this->caution;
}
public function setCaution(float $caution): static
{
$this->caution = $caution;
return $this;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Product;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Product>
*/
class ProductRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Product::class);
}
// /**
// * @return Product[] Returns an array of Product objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Product
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}