diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..84a9d0efc73c00dee4e40d8817cbc2aed69833aa --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +Commands to set up Symfony with DB connection + +If you dont have installed yet + +``` +composer require symfony/orm-pack + +composer require --dev symfony/maker-bundle +``` + +``` +php bin/console doctrine:database:create +php bin/console make:migration +php bin/console doctrine:migrations:migrate + +``` \ No newline at end of file diff --git a/web_app/composer.json b/web_app/composer.json index bc22af86027131fbc897a33022d6d7fb4824a55f..61bf1a00081f7385540bf09ab7db4a8420388e9d 100644 --- a/web_app/composer.json +++ b/web_app/composer.json @@ -67,5 +67,8 @@ "allow-contrib": false, "require": "7.2.*" } + }, + "require-dev": { + "symfony/maker-bundle": "^1.62" } } diff --git a/web_app/config/bundles.php b/web_app/config/bundles.php index c1fa06a6a1872365a0051751113af90dcc47c227..de8898b237f4e71035c0d29d0599b62ac4f16adc 100644 --- a/web_app/config/bundles.php +++ b/web_app/config/bundles.php @@ -4,4 +4,5 @@ return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], + Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], ]; diff --git a/web_app/migrations/Version20250221203107.php b/web_app/migrations/Version20250221203107.php new file mode 100644 index 0000000000000000000000000000000000000000..10602e831e4b5a634b3c2313b51843fa18b027bd --- /dev/null +++ b/web_app/migrations/Version20250221203107.php @@ -0,0 +1,31 @@ +<?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 Version20250221203107 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 INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, price DOUBLE PRECISION NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE product'); + } +} diff --git a/web_app/src/Entity/Product.php b/web_app/src/Entity/Product.php new file mode 100644 index 0000000000000000000000000000000000000000..b78a233594416da1c4612af82dc8cd06eed9c32e --- /dev/null +++ b/web_app/src/Entity/Product.php @@ -0,0 +1,50 @@ +<?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 $name = null; + + #[ORM\Column] + private ?float $price = null; + + public function getId(): ?int + { + return $this->id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getPrice(): ?float + { + return $this->price; + } + + public function setPrice(float $price): static + { + $this->price = $price; + + return $this; + } +} diff --git a/web_app/src/Repository/ProductRepository.php b/web_app/src/Repository/ProductRepository.php new file mode 100644 index 0000000000000000000000000000000000000000..9564bc10fca9ed076a021b3c69054aee6bbe3ba7 --- /dev/null +++ b/web_app/src/Repository/ProductRepository.php @@ -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() + // ; + // } +} diff --git a/web_app/symfony.lock b/web_app/symfony.lock index bb5af909aed2128d74d60f4d2de087cd724446e7..b7d02287042f435c61f251c33fed1bebf47030e1 100644 --- a/web_app/symfony.lock +++ b/web_app/symfony.lock @@ -70,6 +70,15 @@ "src/Kernel.php" ] }, + "symfony/maker-bundle": { + "version": "1.62", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "1.0", + "ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f" + } + }, "symfony/routing": { "version": "7.2", "recipe": {