feat: add id column on entity

This commit is contained in:
Maël Gangloff
2025-02-18 01:29:29 +01:00
parent e7b8ce612e
commit 89a7daf882
9 changed files with 264 additions and 12 deletions

View File

@@ -117,7 +117,7 @@ class Domain
#[SerializedName('oldStatus')]
private Collection $domainStatuses;
#[ORM\Column(nullable: false)]
#[ORM\Column(nullable: false, options: ['default' => false])]
#[Groups(['domain:item', 'domain:list'])]
private ?bool $delegationSigned = null;

View File

@@ -19,7 +19,7 @@ class DomainEntity
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: Entity::class, cascade: ['persist'], inversedBy: 'domainEntities')]
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
#[ORM\JoinColumn(name: 'entity_uid', referencedColumnName: 'id', nullable: false)]
#[Groups(['domain-entity:entity'])]
private ?Entity $entity = null;

View File

@@ -12,6 +12,9 @@ use Symfony\Component\Serializer\Attribute\Groups;
use Symfony\Component\Serializer\Attribute\SerializedName;
#[ORM\Entity(repositoryClass: EntityRepository::class)]
#[ORM\UniqueConstraint(
columns: ['tld_id', 'handle']
)]
#[ApiResource(
operations: [
/*
@@ -21,7 +24,7 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
),
*/
new Get(
uriTemplate: '/entities/{handle}',
uriTemplate: '/entities/{id}',
normalizationContext: [
'groups' => [
'event:list',
@@ -38,6 +41,15 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
class Entity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: Tld::class, inversedBy: 'entities')]
#[ORM\JoinColumn(referencedColumnName: 'tld', nullable: true)]
#[Groups(['entity:list', 'entity:item', 'domain:item'])]
private ?Tld $tld = null;
#[ORM\Column(length: 255)]
#[Groups(['entity:list', 'entity:item', 'domain:item'])]
private ?string $handle = null;
@@ -205,4 +217,28 @@ class Entity
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): static
{
$this->id = $id;
return $this;
}
public function getTld(): ?Tld
{
return $this->tld;
}
public function setTld(?Tld $tld): static
{
$this->tld = $tld;
return $this;
}
}

View File

@@ -7,12 +7,12 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EntityEventRepository::class)]
#[ORM\UniqueConstraint(
columns: ['action', 'date', 'entity_id']
columns: ['action', 'date', 'entity_uid']
)]
class EntityEvent extends Event
{
#[ORM\ManyToOne(targetEntity: Entity::class, inversedBy: 'events')]
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
#[ORM\JoinColumn(name: 'entity_uid', referencedColumnName: 'id', nullable: false)]
private ?Entity $entity = null;
public function getEntity(): ?Entity

View File

@@ -19,7 +19,7 @@ class NameserverEntity
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: Entity::class, cascade: ['persist'], inversedBy: 'nameserverEntities')]
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
#[ORM\JoinColumn(name: 'entity_uid', referencedColumnName: 'id', nullable: false)]
#[Groups(['nameserver-entity:entity'])]
private ?Entity $entity = null;

View File

@@ -70,9 +70,16 @@ class Tld
#[Groups(['tld:item'])]
private ?TldType $type = null;
/**
* @var Collection<int, Entity>
*/
#[ORM\OneToMany(targetEntity: Entity::class, mappedBy: 'tld')]
private Collection $entities;
public function __construct()
{
$this->rdapServers = new ArrayCollection();
$this->entities = new ArrayCollection();
}
/**
@@ -200,4 +207,34 @@ class Tld
return $this;
}
/**
* @return Collection<int, Entity>
*/
public function getEntities(): Collection
{
return $this->entities;
}
public function addEntity(Entity $entity): static
{
if (!$this->entities->contains($entity)) {
$this->entities->add($entity);
$entity->setTld($this);
}
return $this;
}
public function removeEntity(Entity $entity): static
{
if ($this->entities->removeElement($entity)) {
// set the owning side to null (unless already changed)
if ($entity->getTld() === $this) {
$entity->setTld(null);
}
}
return $this;
}
}