Compare commits
No commits in common. "15f8db46a05ac4ccf091b6b18804e34ec05bc496" and "8ebf229d622520d2793e70242302458043961474" have entirely different histories.
15f8db46a0
...
8ebf229d62
8 changed files with 15 additions and 198 deletions
4
ecs.php
4
ecs.php
|
@ -13,7 +13,5 @@ return ECSConfig::configure()
|
||||||
__DIR__ . '/tests',
|
__DIR__ . '/tests',
|
||||||
])
|
])
|
||||||
->withRootFiles()
|
->withRootFiles()
|
||||||
->withRules([
|
->withRules([FinalClassFixer::class])
|
||||||
FinalClassFixer::class,
|
|
||||||
])
|
|
||||||
->withSets([LubiSetList::ECS]);
|
->withSets([LubiSetList::ECS]);
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
<?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 Version20250629160123 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(<<<'SQL'
|
|
||||||
ALTER TABLE order_item ADD COLUMN is_paid BOOLEAN DEFAULT 0 NOT NULL
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
ALTER TABLE order_item ADD COLUMN price_cents INTEGER DEFAULT 0 NOT NULL
|
|
||||||
SQL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(Schema $schema): void
|
|
||||||
{
|
|
||||||
// this down() migration is auto-generated, please modify it to your needs
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
CREATE TEMPORARY TABLE __temp__order_item AS SELECT name, extras, created_by, id, food_order_id, menu_item_id FROM order_item
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
DROP TABLE order_item
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
CREATE TABLE order_item (name VARCHAR(255) NOT NULL, extras VARCHAR(255) DEFAULT NULL, created_by VARCHAR(255) DEFAULT 'nobody' NOT NULL, id BLOB NOT NULL, food_order_id BLOB DEFAULT NULL, menu_item_id BLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_52EA1F09A5D24A7A FOREIGN KEY (food_order_id) REFERENCES food_order (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_52EA1F099AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (id) NOT DEFERRABLE INITIALLY IMMEDIATE)
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
INSERT INTO order_item (name, extras, created_by, id, food_order_id, menu_item_id) SELECT name, extras, created_by, id, food_order_id, menu_item_id FROM __temp__order_item
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
DROP TABLE __temp__order_item
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
CREATE INDEX IDX_52EA1F09A5D24A7A ON order_item (food_order_id)
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
CREATE INDEX IDX_52EA1F099AB44FE0 ON order_item (menu_item_id)
|
|
||||||
SQL);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
<?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 Version20250629160639 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(<<<'SQL'
|
|
||||||
ALTER TABLE menu_item ADD COLUMN price_cents INTEGER DEFAULT 0 NOT NULL
|
|
||||||
SQL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(Schema $schema): void
|
|
||||||
{
|
|
||||||
// this down() migration is auto-generated, please modify it to your needs
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
CREATE TEMPORARY TABLE __temp__menu_item AS SELECT name, deleted_at, id, food_vendor_id, alias_of_id FROM menu_item
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
DROP TABLE menu_item
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
CREATE TABLE menu_item (name VARCHAR(255) NOT NULL, deleted_at DATETIME DEFAULT NULL, id BLOB NOT NULL, food_vendor_id BLOB NOT NULL, alias_of_id BLOB DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_D754D5506EF983E8 FOREIGN KEY (food_vendor_id) REFERENCES food_vendor (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D754D55061F0AFC5 FOREIGN KEY (alias_of_id) REFERENCES menu_item (id) NOT DEFERRABLE INITIALLY IMMEDIATE)
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
INSERT INTO menu_item (name, deleted_at, id, food_vendor_id, alias_of_id) SELECT name, deleted_at, id, food_vendor_id, alias_of_id FROM __temp__menu_item
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
DROP TABLE __temp__menu_item
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
CREATE INDEX IDX_D754D5506EF983E8 ON menu_item (food_vendor_id)
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
CREATE INDEX IDX_D754D55061F0AFC5 ON menu_item (alias_of_id)
|
|
||||||
SQL);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -75,6 +75,19 @@ final class OrderItemController extends AbstractController
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$menuItem = $menuItemRepository->findOneBy([
|
||||||
|
'name' => $orderItem->getName(),
|
||||||
|
'foodVendor' => $foodOrder->getFoodVendor(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($menuItem === null) {
|
||||||
|
$menuItem = new MenuItem;
|
||||||
|
$menuItem->setName($orderItem->getName());
|
||||||
|
$menuItem->setFoodVendor($foodOrder->getFoodVendor());
|
||||||
|
$entityManager->persist($menuItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderItem->setMenuItem($menuItem);
|
||||||
$orderItem->setFoodOrder($foodOrder);
|
$orderItem->setFoodOrder($foodOrder);
|
||||||
$entityManager->persist($orderItem);
|
$entityManager->persist($orderItem);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
|
|
|
@ -35,11 +35,6 @@ class MenuItem
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
private string|null $name = null;
|
private string|null $name = null;
|
||||||
|
|
||||||
#[ORM\Column(type: 'integer', options: [
|
|
||||||
'default' => 0,
|
|
||||||
])]
|
|
||||||
private int $priceCents = 0;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||||
|
@ -100,11 +95,6 @@ class MenuItem
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPriceCents(): int
|
|
||||||
{
|
|
||||||
return $this->priceCents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isDeleted(): bool
|
public function isDeleted(): bool
|
||||||
{
|
{
|
||||||
return $this->getDeletedAt() instanceof DateTimeImmutable;
|
return $this->getDeletedAt() instanceof DateTimeImmutable;
|
||||||
|
@ -147,10 +137,4 @@ class MenuItem
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPriceCents(int $priceCents): self
|
|
||||||
{
|
|
||||||
$this->priceCents = $priceCents;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,6 @@ class OrderItem
|
||||||
#[ORM\ManyToOne(inversedBy: 'orderItems')]
|
#[ORM\ManyToOne(inversedBy: 'orderItems')]
|
||||||
private FoodOrder|null $foodOrder = null;
|
private FoodOrder|null $foodOrder = null;
|
||||||
|
|
||||||
#[Groups('food_order:latest')]
|
|
||||||
#[ORM\Column(type: 'boolean', options: [
|
|
||||||
'default' => false,
|
|
||||||
])]
|
|
||||||
private bool $isPaid = false;
|
|
||||||
|
|
||||||
#[Groups(['food_order:latest'])]
|
#[Groups(['food_order:latest'])]
|
||||||
#[ORM\JoinColumn(nullable: false)]
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
#[ORM\ManyToOne]
|
#[ORM\ManyToOne]
|
||||||
|
@ -43,12 +37,6 @@ class OrderItem
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
private string|null $name = null;
|
private string|null $name = null;
|
||||||
|
|
||||||
#[Groups('food_order:latest')]
|
|
||||||
#[ORM\Column(type: 'integer', options: [
|
|
||||||
'default' => 0,
|
|
||||||
])]
|
|
||||||
private int $priceCents = 0;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Groups(['food_order:latest'])]
|
#[Groups(['food_order:latest'])]
|
||||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||||
|
@ -90,16 +78,6 @@ class OrderItem
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPriceCents(): int
|
|
||||||
{
|
|
||||||
return $this->priceCents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isPaid(): bool
|
|
||||||
{
|
|
||||||
return $this->isPaid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCreatedBy(string $createdBy): static
|
public function setCreatedBy(string $createdBy): static
|
||||||
{
|
{
|
||||||
$this->createdBy = $createdBy;
|
$this->createdBy = $createdBy;
|
||||||
|
@ -121,12 +99,6 @@ class OrderItem
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIsPaid(bool $isPaid): self
|
|
||||||
{
|
|
||||||
$this->isPaid = $isPaid;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMenuItem(MenuItem|null $menuItem): static
|
public function setMenuItem(MenuItem|null $menuItem): static
|
||||||
{
|
{
|
||||||
$this->menuItem = $menuItem;
|
$this->menuItem = $menuItem;
|
||||||
|
@ -141,10 +113,4 @@ class OrderItem
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPriceCents(int $priceCents): self
|
|
||||||
{
|
|
||||||
$this->priceCents = $priceCents;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\EventListener;
|
|
||||||
|
|
||||||
use App\Entity\MenuItem;
|
|
||||||
use App\Entity\OrderItem;
|
|
||||||
use App\Repository\MenuItemRepository;
|
|
||||||
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
|
|
||||||
use Doctrine\ORM\Event\PrePersistEventArgs;
|
|
||||||
use Doctrine\ORM\Events;
|
|
||||||
|
|
||||||
#[AsEntityListener(event: Events::prePersist, method: 'prePersist', entity: OrderItem::class)]
|
|
||||||
final readonly class OrderItemPrePersist
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private MenuItemRepository $menuItemRepository,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function prePersist(OrderItem $orderItem, PrePersistEventArgs $eventArgs): void
|
|
||||||
{
|
|
||||||
$menuItem = $this->menuItemRepository->findOneBy([
|
|
||||||
'name' => $orderItem->getName(),
|
|
||||||
'foodVendor' => $orderItem->getFoodOrder()
|
|
||||||
->getFoodVendor(),
|
|
||||||
]);
|
|
||||||
if ($menuItem === null) {
|
|
||||||
$menuItem = new MenuItem;
|
|
||||||
$menuItem->setName($orderItem->getName());
|
|
||||||
$menuItem->setFoodVendor($orderItem->getFoodOrder()->getFoodVendor());
|
|
||||||
$eventArgs->getObjectManager()
|
|
||||||
->persist($menuItem);
|
|
||||||
}
|
|
||||||
$orderItem->setMenuItem($menuItem);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -182,7 +182,7 @@ describe(OrderItemController::class, function (): void {
|
||||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||||
|
|
||||||
$this->assertSame(1, $this->repository->count([]));
|
$this->assertSame(1, $this->repository->count([]));
|
||||||
$this->assertSame(2, $this->menuItemRepository->count([]));
|
$this->assertSame(3, $this->menuItemRepository->count([]));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue