#42: allow updates to menuitems

This commit is contained in:
lubiana 2024-07-29 13:04:57 +02:00
parent 0068654885
commit 674adcba60
No known key found for this signature in database
14 changed files with 258 additions and 7 deletions

View file

@ -88,9 +88,14 @@ class FoodVendor
/**
* @return Collection<int, MenuItem>
*/
public function getMenuItems(): Collection
public function getMenuItems(bool $withDeleted = false): Collection
{
return $this->menuItems;
if ($withDeleted) {
return $this->menuItems;
}
return $this->menuItems->filter(
static fn(MenuItem $item): bool => $item->isDeleted() === false
);
}
public function addMenuItem(MenuItem $menuItem): static

View file

@ -3,6 +3,7 @@
namespace App\Entity;
use App\Repository\MenuItemRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
@ -24,6 +25,9 @@ class MenuItem
#[ORM\JoinColumn(nullable: false)]
private FoodVendor|null $foodVendor = null;
#[ORM\Column(nullable: true)]
private DateTimeImmutable|null $deletedAt = null;
public function getId(): Ulid|null
{
return $this->id;
@ -52,4 +56,27 @@ class MenuItem
return $this;
}
public function isDeleted(): bool
{
return $this->getDeletedAt() instanceof DateTimeImmutable;
}
public function delete(): static
{
$this->setDeletedAt();
return $this;
}
public function getDeletedAt(): DateTimeImmutable|null
{
return $this->deletedAt;
}
public function setDeletedAt(DateTimeImmutable|null $deletedAt = new DateTimeImmutable): static
{
$this->deletedAt = $deletedAt;
return $this;
}
}