Refactor Relationship entity to use traits

The Relationship entity in ChillPersonBundle has been refactored to use TrackCreationTrait and TrackUpdateTrait. As a result, the redundant code for handling creation and update tracking has been removed. This change will simplify future development by reusing core functionality from the trait instead of manually controlling the process in each entity.
This commit is contained in:
Julien Fastré 2024-04-08 12:13:39 +02:00
parent 5be85a4fc6
commit e8c7623a1e
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -12,8 +12,9 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity\Relationships; namespace Chill\PersonBundle\Entity\Relationships;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Validator\Constraints\Relationship\RelationshipNoDuplicate; use Chill\PersonBundle\Validator\Constraints\Relationship\RelationshipNoDuplicate;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
@ -30,12 +31,8 @@ use Symfony\Component\Validator\Constraints as Assert;
#[RelationshipNoDuplicate] #[RelationshipNoDuplicate]
class Relationship implements TrackCreationInterface, TrackUpdateInterface class Relationship implements TrackCreationInterface, TrackUpdateInterface
{ {
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)] use TrackCreationTrait;
private ?\DateTimeImmutable $createdAt = null; use TrackUpdateTrait;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: false)]
private ?User $createdBy = null;
#[Assert\NotNull] #[Assert\NotNull]
#[Serializer\Groups(['read', 'write'])] #[Serializer\Groups(['read', 'write'])]
@ -66,22 +63,6 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
#[ORM\JoinColumn(nullable: false)] #[ORM\JoinColumn(nullable: false)]
private ?Person $toPerson = null; private ?Person $toPerson = null;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $updatedBy = null;
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function getFromPerson(): ?Person public function getFromPerson(): ?Person
{ {
return $this->fromPerson; return $this->fromPerson;
@ -134,30 +115,6 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
return $this->toPerson; return $this->toPerson;
} }
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function setCreatedBy(?User $user): self
{
$this->createdBy = $user;
return $this;
}
public function setFromPerson(?Person $fromPerson): self public function setFromPerson(?Person $fromPerson): self
{ {
$this->fromPerson = $fromPerson; $this->fromPerson = $fromPerson;
@ -185,18 +142,4 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
return $this; return $this;
} }
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
} }