Feat: Make some entities soft-deletable

This commit is contained in:
Björn Fromme
2023-10-20 17:17:21 +02:00
parent 168a69c103
commit d7bbb4bb29
27 changed files with 213 additions and 63 deletions
+3 -1
View File
@@ -3,6 +3,7 @@
namespace App\Entity;
use App\Entity\Traits\BlameableEntity;
use App\Entity\Traits\SoftDeletableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\AssignmentRepository;
use Carbon\CarbonPeriod;
@@ -14,10 +15,11 @@ use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: AssignmentRepository::class)]
class Assignment implements BlameableEntityInterface, TimestampableEntityInterface
class Assignment implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
{
use BlameableEntity;
use TimestampableEntity;
use SoftDeletableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
+3 -1
View File
@@ -3,6 +3,7 @@
namespace App\Entity;
use App\Entity\Traits\BlameableEntity;
use App\Entity\Traits\SoftDeletableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\AvailabilityRepository;
use Doctrine\Common\Collections\ArrayCollection;
@@ -12,10 +13,11 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: AvailabilityRepository::class)]
class Availability implements BlameableEntityInterface, TimestampableEntityInterface
class Availability implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
{
use BlameableEntity;
use TimestampableEntity;
use SoftDeletableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
+6 -1
View File
@@ -2,13 +2,18 @@
namespace App\Entity;
use App\Entity\Traits\SoftDeletableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\DestinationRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: DestinationRepository::class)]
class Destination
class Destination implements TimestampableEntityInterface, SoftDeletableEntityInterface
{
use TimestampableEntity;
use SoftDeletableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
+3 -1
View File
@@ -3,6 +3,7 @@
namespace App\Entity;
use App\Entity\Traits\BlameableEntity;
use App\Entity\Traits\SoftDeletableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\DispositionRepository;
use Doctrine\Common\Collections\ArrayCollection;
@@ -12,10 +13,11 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: DispositionRepository::class)]
class Disposition implements BlameableEntityInterface, TimestampableEntityInterface
class Disposition implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
{
use BlameableEntity;
use TimestampableEntity;
use SoftDeletableEntity;
public const STATUS_NEW = 'new';
public const STATUS_CHECKING_CONTRACT = 'checking_contract';
+3 -1
View File
@@ -3,16 +3,18 @@
namespace App\Entity;
use App\Entity\Traits\BlameableEntity;
use App\Entity\Traits\SoftDeletableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\FeeRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: FeeRepository::class)]
class Fee implements BlameableEntityInterface, TimestampableEntityInterface
class Fee implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
{
use BlameableEntity;
use TimestampableEntity;
use SoftDeletableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
+3 -1
View File
@@ -3,6 +3,7 @@
namespace App\Entity;
use App\Entity\Traits\BlameableEntity;
use App\Entity\Traits\SoftDeletableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\JobProfileRepository;
use Doctrine\Common\Collections\ArrayCollection;
@@ -13,10 +14,11 @@ use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: JobProfileRepository::class)]
class JobProfile implements BlameableEntityInterface, TimestampableEntityInterface
class JobProfile implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
{
use BlameableEntity;
use TimestampableEntity;
use SoftDeletableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -0,0 +1,10 @@
<?php
namespace App\Entity;
interface SoftDeletableEntityInterface
{
public function getDeletedAt(): ?\DateTimeImmutable;
public function setDeletedAt(\DateTimeImmutable $createdAt): static;
}
+4 -4
View File
@@ -4,11 +4,11 @@ namespace App\Entity;
interface TimestampableEntityInterface
{
public function getCreatedAt();
public function getCreatedAt(): \DateTimeImmutable;
public function setCreatedAt(\DateTimeImmutable $createdAt);
public function setCreatedAt(\DateTimeImmutable $createdAt): static;
public function getUpdatedAt();
public function getUpdatedAt(): ?\DateTimeImmutable;
public function setUpdatedAt(\DateTimeImmutable $updatedAt);
public function setUpdatedAt(\DateTimeImmutable $updatedAt): static;
}
+3 -1
View File
@@ -3,6 +3,7 @@
namespace App\Entity;
use App\Entity\Traits\BlameableEntity;
use App\Entity\Traits\SoftDeletableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\TrainingRepository;
use Doctrine\Common\Collections\ArrayCollection;
@@ -10,10 +11,11 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TrainingRepository::class)]
class Training implements BlameableEntityInterface, TimestampableEntityInterface
class Training implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
{
use BlameableEntity;
use TimestampableEntity;
use SoftDeletableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace App\Entity\Traits;
use Doctrine\ORM\Mapping as ORM;
trait SoftDeletableEntity
{
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $deletedAt = null;
public function getDeletedAt(): \DateTimeImmutable
{
return $this->deletedAt;
}
public function setDeletedAt(\DateTimeImmutable $deletedAt): static
{
$this->deletedAt = $deletedAt;
return $this;
}
public function setDeleted(): static
{
$this->setDeletedAt(new \DateTimeImmutable());
return $this;
}
public function isDeleted(): bool
{
return null !== $this->getDeletedAt();
}
}