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;
}
}