feat: add updatedAt on DomainEntity

This commit is contained in:
Maël Gangloff
2024-08-06 19:05:02 +02:00
parent 1fd5dd90db
commit e46851ca54
4 changed files with 64 additions and 2 deletions

View File

@@ -27,6 +27,15 @@ class DomainEntity
#[Groups(['domain-entity:entity', 'domain-entity:domain'])]
private array $roles = [];
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
#[Groups(['domain-entity:entity', 'domain-entity:domain'])]
private ?\DateTimeImmutable $updatedAt = null;
public function __construct()
{
$this->updatedAt = new \DateTimeImmutable('now');
}
public function getDomain(): ?Domain
{
return $this->domain;
@@ -65,4 +74,23 @@ class DomainEntity
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function updateTimestamps(): void
{
$this->setUpdatedAt(new \DateTimeImmutable('now'));
}
}