This commit is contained in:
lubiana 2025-06-29 19:26:29 +02:00
parent bbc56a9af7
commit 1f9562d36b
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
13 changed files with 525 additions and 507 deletions

View file

@ -47,32 +47,32 @@ use function iterator_to_array;
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
class FoodOrder
{
#[ORM\Column(nullable: true)]
#[Groups(['food_order:read'])]
#[ORM\Column(nullable: true)]
private DateTimeImmutable|null $closedAt = null;
#[ORM\ManyToOne(inversedBy: 'foodOrders')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['food_order:read'])]
#[ORM\Column(length: 255, options: [
'default' => 'nobody',
])]
private string|null $createdBy = 'nobody';
#[Groups(['food_order:read', 'food_order:latest'])]
#[ORM\JoinColumn(nullable: false)]
#[ORM\ManyToOne(inversedBy: 'foodOrders')]
private FoodVendor|null $foodVendor = null;
/**
* @var Collection<int, OrderItem>
*/
#[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'foodOrder', orphanRemoval: true)]
#[Groups(['food_order:read', 'food_order:latest'])]
#[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'foodOrder', orphanRemoval: true)]
private Collection $orderItems;
#[ORM\Column(length: 255, options: [
'default' => 'nobody',
])]
#[Groups(['food_order:read'])]
private string|null $createdBy = 'nobody';
public function __construct(
#[ORM\Id]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[Groups(['food_order:read'])]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\Id]
private Ulid|null $id = new Ulid
) {
$this->id ??= new Ulid;
@ -80,9 +80,24 @@ class FoodOrder
$this->open();
}
public function getId(): Ulid|null
public function addOrderItem(OrderItem $orderItem): static
{
return $this->id;
if (! $this->orderItems->contains($orderItem)) {
$this->orderItems->add($orderItem);
$orderItem->setFoodOrder($this);
}
return $this;
}
public function close(): static
{
return $this->setClosedAt(new DateTimeImmutable);
}
public function getClosedAt(): DateTimeImmutable|null
{
return $this->closedAt;
}
#[Groups(['food_order:read'])]
@ -91,35 +106,9 @@ class FoodOrder
return $this->id->getDateTime();
}
public function getClosedAt(): DateTimeImmutable|null
public function getCreatedBy(): string|null
{
return $this->closedAt;
}
public function setClosedAt(DateTimeImmutable|null $closedAt = null): static
{
$this->closedAt = $closedAt;
return $this;
}
public function isClosed(): bool
{
if (! $this->closedAt instanceof DateTimeImmutable) {
return false;
}
return $this->closedAt < new DateTimeImmutable;
}
public function close(): static
{
return $this->setClosedAt(new DateTimeImmutable);
}
public function open(): static
{
$this->closedAt = (new DateTimeImmutable)->add(new DateInterval('PT1H'));
return $this;
return $this->createdBy;
}
public function getFoodVendor(): FoodVendor|null
@ -127,11 +116,9 @@ class FoodOrder
return $this->foodVendor;
}
public function setFoodVendor(FoodVendor|null $foodVendor): static
public function getId(): Ulid|null
{
$this->foodVendor = $foodVendor;
return $this;
return $this->id;
}
/**
@ -159,13 +146,17 @@ class FoodOrder
);
}
public function addOrderItem(OrderItem $orderItem): static
public function isClosed(): bool
{
if (! $this->orderItems->contains($orderItem)) {
$this->orderItems->add($orderItem);
$orderItem->setFoodOrder($this);
if (! $this->closedAt instanceof DateTimeImmutable) {
return false;
}
return $this->closedAt < new DateTimeImmutable;
}
public function open(): static
{
$this->closedAt = (new DateTimeImmutable)->add(new DateInterval('PT1H'));
return $this;
}
@ -179,9 +170,11 @@ class FoodOrder
return $this;
}
public function getCreatedBy(): string|null
public function setClosedAt(DateTimeImmutable|null $closedAt = null): static
{
return $this->createdBy;
$this->closedAt = $closedAt;
return $this;
}
public function setCreatedBy(string $createdBy): static
@ -190,4 +183,11 @@ class FoodOrder
return $this;
}
public function setFoodVendor(FoodVendor|null $foodVendor): static
{
$this->foodVendor = $foodVendor;
return $this;
}
}

View file

@ -16,19 +16,17 @@ use Symfony\Component\Validator\Constraints\Length;
use function mb_strlen;
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
#[ApiResource]
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
class FoodVendor
{
#[ORM\Column(length: 50)]
/**
* String of emojis (max 30 characters)
*/
#[Groups(['food_order:latest', 'food_vendor:read'])]
private string|null $name = null;
#[ORM\Column(length: 50, nullable: true, options: [
'default' => '',
])]
#[Groups(['food_order:latest', 'food_vendor:read'])]
private string|null $phone = null;
#[Length(max: 10)]
#[ORM\Column(length: 30, nullable: true)]
private string|null $emojis = null;
/**
* @var Collection<int, FoodOrder>
@ -42,24 +40,26 @@ class FoodVendor
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'foodVendor', orphanRemoval: true)]
private Collection $menuItems;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['food_order:latest'])]
#[ORM\Column(length: 255, nullable: true)]
private string|null $menuLink = null;
/**
* String of emojis (max 30 characters)
*/
#[ORM\Column(length: 30, nullable: true)]
#[Groups(['food_order:latest', 'food_vendor:read'])]
#[Length(max: 10)]
private string|null $emojis = null;
#[ORM\Column(length: 50)]
private string|null $name = null;
#[Groups(['food_order:latest', 'food_vendor:read'])]
#[ORM\Column(length: 50, nullable: true, options: [
'default' => '',
])]
private string|null $phone = null;
public function __construct(
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[Groups(['food_order:latest'])]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['food_order:latest'])]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Id]
private Ulid|null $id = new Ulid
) {
$this->id ??= new Ulid;
@ -67,31 +67,6 @@ class FoodVendor
$this->menuItems = new ArrayCollection;
}
public function getId(): Ulid|null
{
return $this->id;
}
public function getName(): string|null
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, FoodOrder>
*/
public function getFoodOrders(): Collection
{
return $this->foodOrders;
}
public function addFoodOrder(FoodOrder $foodOrder): static
{
if (! $this->foodOrders->contains($foodOrder)) {
@ -102,16 +77,34 @@ class FoodVendor
return $this;
}
public function removeFoodOrder(FoodOrder $foodOrder): static
public function addMenuItem(MenuItem $menuItem): static
{
// set the owning side to null (unless already changed)
if ($this->foodOrders->removeElement($foodOrder)) {
$foodOrder->setFoodVendor(null);
if (! $this->menuItems->contains($menuItem)) {
$this->menuItems->add($menuItem);
$menuItem->setFoodVendor($this);
}
return $this;
}
public function getEmojis(): string|null
{
return $this->emojis;
}
/**
* @return Collection<int, FoodOrder>
*/
public function getFoodOrders(): Collection
{
return $this->foodOrders;
}
public function getId(): Ulid|null
{
return $this->id;
}
/**
* @return Collection<int, MenuItem>
*/
@ -125,11 +118,26 @@ class FoodVendor
);
}
public function addMenuItem(MenuItem $menuItem): static
public function getMenuLink(): string|null
{
if (! $this->menuItems->contains($menuItem)) {
$this->menuItems->add($menuItem);
$menuItem->setFoodVendor($this);
return $this->menuLink;
}
public function getName(): string|null
{
return $this->name;
}
public function getPhone(): string|null
{
return $this->phone;
}
public function removeFoodOrder(FoodOrder $foodOrder): static
{
// set the owning side to null (unless already changed)
if ($this->foodOrders->removeElement($foodOrder)) {
$foodOrder->setFoodVendor(null);
}
return $this;
@ -145,34 +153,6 @@ class FoodVendor
return $this;
}
public function getMenuLink(): string|null
{
return $this->menuLink;
}
public function setMenuLink(string|null $menuLink): static
{
$this->menuLink = $menuLink;
return $this;
}
public function getPhone(): string|null
{
return $this->phone;
}
public function setPhone(string|null $phone): static
{
$this->phone = $phone;
return $this;
}
public function getEmojis(): string|null
{
return $this->emojis;
}
public function setEmojis(string|null $emojis): static
{
if ($emojis !== null && mb_strlen($emojis) > 30) {
@ -182,4 +162,24 @@ class FoodVendor
$this->emojis = $emojis;
return $this;
}
public function setMenuLink(string|null $menuLink): static
{
$this->menuLink = $menuLink;
return $this;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function setPhone(string|null $phone): static
{
$this->phone = $phone;
return $this;
}
}

View file

@ -16,108 +16,36 @@ use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
class MenuItem
{
#[ORM\Column(length: 255)]
private string|null $name = null;
#[ORM\ManyToOne(inversedBy: 'menuItems')]
#[ORM\JoinColumn(nullable: false)]
private FoodVendor|null $foodVendor = null;
#[ORM\Column(nullable: true)]
private DateTimeImmutable|null $deletedAt = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'aliases')]
private self|null $aliasOf = null;
/**
* @var Collection<int, self>
*/
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'aliasOf')]
private Collection $aliases;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'aliases')]
private self|null $aliasOf = null;
#[ORM\Column(nullable: true)]
private DateTimeImmutable|null $deletedAt = null;
#[ORM\JoinColumn(nullable: false)]
#[ORM\ManyToOne(inversedBy: 'menuItems')]
private FoodVendor|null $foodVendor = null;
#[ORM\Column(length: 255)]
private string|null $name = null;
public function __construct(
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Id]
private Ulid|null $id = new Ulid
) {
$this->id ??= new Ulid;
$this->aliases = new ArrayCollection;
}
public function getId(): Ulid|null
{
return $this->id;
}
public function getName(): string|null
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getFoodVendor(): FoodVendor|null
{
return $this->foodVendor;
}
public function setFoodVendor(FoodVendor|null $foodVendor): static
{
$this->foodVendor = $foodVendor;
return $this;
}
public function isDeleted(): bool
{
return $this->getDeletedAt() instanceof DateTimeImmutable;
}
public function delete(): static
{
$this->setDeletedAt(new DateTimeImmutable);
return $this;
}
public function getDeletedAt(): DateTimeImmutable|null
{
return $this->deletedAt;
}
public function setDeletedAt(DateTimeImmutable|null $deletedAt = new DateTimeImmutable): static
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getAliasOf(): self|null
{
return $this->aliasOf;
}
public function setAliasOf(self|null $aliasOf): static
{
$this->aliasOf = $aliasOf;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getAliases(): Collection
{
return $this->aliases;
}
public function addAlias(self $alias): static
{
if (! $this->aliases->contains($alias)) {
@ -128,6 +56,50 @@ class MenuItem
return $this;
}
public function delete(): static
{
$this->setDeletedAt(new DateTimeImmutable);
return $this;
}
/**
* @return Collection<int, self>
*/
public function getAliases(): Collection
{
return $this->aliases;
}
public function getAliasOf(): self|null
{
return $this->aliasOf;
}
public function getDeletedAt(): DateTimeImmutable|null
{
return $this->deletedAt;
}
public function getFoodVendor(): FoodVendor|null
{
return $this->foodVendor;
}
public function getId(): Ulid|null
{
return $this->id;
}
public function getName(): string|null
{
return $this->name;
}
public function isDeleted(): bool
{
return $this->getDeletedAt() instanceof DateTimeImmutable;
}
public function removeAlias(self $alias): static
{
// set the owning side to null (unless already changed)
@ -137,4 +109,32 @@ class MenuItem
return $this;
}
public function setAliasOf(self|null $aliasOf): static
{
$this->aliasOf = $aliasOf;
return $this;
}
public function setDeletedAt(DateTimeImmutable|null $deletedAt = new DateTimeImmutable): static
{
$this->deletedAt = $deletedAt;
return $this;
}
public function setFoodVendor(FoodVendor|null $foodVendor): static
{
$this->foodVendor = $foodVendor;
return $this;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
}

View file

@ -14,62 +14,77 @@ use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
class OrderItem
{
#[ORM\Column(length: 255)]
#[Groups(['food_order:latest'])]
private string|null $name = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['food_order:latest'])]
private string|null $extras = null;
#[ORM\ManyToOne(inversedBy: 'orderItems')]
#[ORM\JoinColumn(nullable: true)]
private FoodOrder|null $foodOrder = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['food_order:latest'])]
private MenuItem|null $menuItem = null;
#[ORM\Column(length: 255, options: [
'default' => 'nobody',
])]
#[Groups(['food_order:latest'])]
private string|null $createdBy = 'nobody';
#[Groups(['food_order:latest'])]
#[ORM\Column(length: 255, nullable: true)]
private string|null $extras = null;
#[ORM\JoinColumn(nullable: true)]
#[ORM\ManyToOne(inversedBy: 'orderItems')]
private FoodOrder|null $foodOrder = null;
#[Groups(['food_order:latest'])]
#[ORM\JoinColumn(nullable: false)]
#[ORM\ManyToOne]
private MenuItem|null $menuItem = null;
#[Groups(['food_order:latest'])]
#[ORM\Column(length: 255)]
private string|null $name = null;
public function __construct(
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[Groups(['food_order:latest'])]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['food_order:latest'])]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Id]
private Ulid|null $id = new Ulid
) {
$this->id ??= new Ulid;
}
public function getCreatedBy(): string|null
{
return $this->createdBy;
}
public function getExtras(): string|null
{
return $this->extras;
}
public function getFoodOrder(): FoodOrder|null
{
return $this->foodOrder;
}
public function getId(): Ulid|null
{
return $this->id;
}
public function getMenuItem(): MenuItem|null
{
return $this->menuItem;
}
public function getName(): string|null
{
return $this->name;
}
public function setName(string $name): static
public function setCreatedBy(string $createdBy): static
{
$this->name = $name;
$this->createdBy = $createdBy;
return $this;
}
public function getExtras(): string|null
{
return $this->extras;
}
public function setExtras(string|null $extras): static
{
$this->extras = $extras;
@ -77,11 +92,6 @@ class OrderItem
return $this;
}
public function getFoodOrder(): FoodOrder|null
{
return $this->foodOrder;
}
public function setFoodOrder(FoodOrder|null $foodOrder): static
{
$this->foodOrder = $foodOrder;
@ -89,11 +99,6 @@ class OrderItem
return $this;
}
public function getMenuItem(): MenuItem|null
{
return $this->menuItem;
}
public function setMenuItem(MenuItem|null $menuItem): static
{
$this->menuItem = $menuItem;
@ -102,14 +107,9 @@ class OrderItem
return $this;
}
public function getCreatedBy(): string|null
public function setName(string $name): static
{
return $this->createdBy;
}
public function setCreatedBy(string $createdBy): static
{
$this->createdBy = $createdBy;
$this->name = $name;
return $this;
}