mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add API Platform
This commit is contained in:
0
src/ApiResource/.gitignore
vendored
Normal file
0
src/ApiResource/.gitignore
vendored
Normal file
@@ -2,35 +2,60 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Repository\DomainRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: DomainRepository::class)]
|
||||
#[UniqueEntity('handle')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/domains/{ldhName}',
|
||||
normalizationContext: ['groups' => [
|
||||
'domain:item',
|
||||
'event:list',
|
||||
'entity:list',
|
||||
'domain-entity:entity',
|
||||
'nameserver-entity:nameserver',
|
||||
'nameserver:item',
|
||||
]]
|
||||
)
|
||||
]
|
||||
)]
|
||||
class Domain
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['domain:item'])]
|
||||
private ?string $ldhName = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['domain:item'])]
|
||||
private ?string $handle = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, DomainEvent>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: DomainEvent::class, mappedBy: 'domain', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[Groups(['domain:item'])]
|
||||
private Collection $events;
|
||||
|
||||
/**
|
||||
* @var Collection<int, DomainEntity>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: DomainEntity::class, mappedBy: 'domain', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[Groups(['domain:item'])]
|
||||
private Collection $domainEntities;
|
||||
|
||||
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
|
||||
#[Groups(['domain:item'])]
|
||||
private array $status = [];
|
||||
|
||||
/**
|
||||
@@ -47,6 +72,7 @@ class Domain
|
||||
joinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name')],
|
||||
inverseJoinColumns: [new ORM\JoinColumn(name: 'nameserver_ldh_name', referencedColumnName: 'ldh_name')]
|
||||
)]
|
||||
#[Groups(['domain:item'])]
|
||||
private Collection $nameservers;
|
||||
|
||||
public function __construct()
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Config\DomainRole;
|
||||
use App\Repository\DomainEntityRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: DomainEntityRepository::class)]
|
||||
class DomainEntity
|
||||
@@ -13,14 +14,17 @@ class DomainEntity
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(targetEntity: Domain::class, cascade: ['persist'], inversedBy: 'domainEntities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'ldh_name', nullable: false)]
|
||||
#[Groups('domain-entity:domain')]
|
||||
private ?Domain $domain = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(targetEntity: Entity::class, cascade: ['persist'], inversedBy: 'domainEntities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
#[Groups(['domain-entity:entity'])]
|
||||
private ?Entity $entity = null;
|
||||
|
||||
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainRole::class)]
|
||||
#[Groups(['domain-entity:entity', 'domain-entity:domain'])]
|
||||
private array $roles = [];
|
||||
|
||||
|
||||
|
||||
@@ -2,10 +2,22 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Repository\DomainEventRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: DomainEventRepository::class)]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/events/domain/{id}',
|
||||
shortName: 'Domain Event',
|
||||
class: DomainEvent::class,
|
||||
normalizationContext: ['groups' => ['event:list']]
|
||||
)
|
||||
]
|
||||
)]
|
||||
class DomainEvent extends Event
|
||||
{
|
||||
#[ORM\ManyToOne(targetEntity: Domain::class, cascade: ['persist'], inversedBy: 'events')]
|
||||
|
||||
@@ -2,39 +2,67 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use App\Repository\EntityRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: EntityRepository::class)]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: '/entities',
|
||||
normalizationContext: ['groups' => ['entity:list', 'event:list']]
|
||||
),
|
||||
new Get(
|
||||
uriTemplate: '/entities/{handle}',
|
||||
normalizationContext: [
|
||||
'groups' => [
|
||||
'event:list',
|
||||
'entity:item',
|
||||
'domain-entity:domain',
|
||||
'nameserver-entity:nameserver'
|
||||
]
|
||||
]
|
||||
)
|
||||
]
|
||||
)]
|
||||
class Entity
|
||||
{
|
||||
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['entity:list', 'entity:item'])]
|
||||
private ?string $handle = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, DomainEntity>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: DomainEntity::class, mappedBy: 'entity', orphanRemoval: true)]
|
||||
#[Groups(['entity:item'])]
|
||||
private Collection $domainEntities;
|
||||
|
||||
/**
|
||||
* @var Collection<int, NameserverEntity>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: NameserverEntity::class, mappedBy: 'entity')]
|
||||
#[Groups(['entity:item'])]
|
||||
private Collection $nameserverEntities;
|
||||
|
||||
/**
|
||||
* @var Collection<int, EntityEvent>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: EntityEvent::class, mappedBy: 'entity', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[Groups(['entity:list', 'entity:item'])]
|
||||
private Collection $events;
|
||||
|
||||
#[ORM\Column]
|
||||
#[Groups(['entity:item'])]
|
||||
private array $jCard = [];
|
||||
|
||||
public function __construct()
|
||||
|
||||
@@ -2,10 +2,24 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Repository\EntityEventRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: EntityEventRepository::class)]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/events/entity/{id}',
|
||||
shortName: 'Entity Event',
|
||||
class: EntityEvent::class,
|
||||
normalizationContext: [
|
||||
'groups' => ['event:list']
|
||||
]
|
||||
)
|
||||
]
|
||||
)]
|
||||
class EntityEvent extends Event
|
||||
{
|
||||
|
||||
@@ -14,7 +28,6 @@ class EntityEvent extends Event
|
||||
private ?Entity $entity = null;
|
||||
|
||||
|
||||
|
||||
public function getEntity(): ?Entity
|
||||
{
|
||||
return $this->entity;
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Config\EventAction;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\MappedSuperclass]
|
||||
class Event
|
||||
@@ -15,9 +18,11 @@ class Event
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(enumType: EventAction::class)]
|
||||
#[Groups(['event:list'])]
|
||||
private ?EventAction $action = null;
|
||||
|
||||
#[ORM\Column(type: 'datetime_immutable')]
|
||||
#[Groups(['event:list'])]
|
||||
private ?DateTimeImmutable $date = null;
|
||||
|
||||
|
||||
|
||||
@@ -2,23 +2,42 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Repository\NameserverRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: NameserverRepository::class)]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/nameservers/{ldhName}',
|
||||
normalizationContext: [
|
||||
'groups' => [
|
||||
'nameserver:item',
|
||||
'entity:list',
|
||||
'nameserver-entity:entity'
|
||||
]
|
||||
]
|
||||
)
|
||||
]
|
||||
)]
|
||||
class Nameserver
|
||||
{
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['nameserver:item'])]
|
||||
private ?string $ldhName = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, NameserverEntity>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: NameserverEntity::class, mappedBy: 'nameserver', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[Groups(['nameserver:item'])]
|
||||
private Collection $nameserverEntities;
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Config\DomainRole;
|
||||
use App\Repository\NameserverEntityRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: NameserverEntityRepository::class)]
|
||||
class NameserverEntity
|
||||
@@ -13,18 +14,22 @@ class NameserverEntity
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(targetEntity: Nameserver::class, cascade: ['persist'], inversedBy: 'nameserverEntities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'ldh_name', nullable: false)]
|
||||
#[Groups(['nameserver-entity:nameserver'])]
|
||||
private ?Nameserver $nameserver = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(targetEntity: Entity::class, cascade: ['persist'], inversedBy: 'nameserverEntities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
#[Groups(['nameserver-entity:entity'])]
|
||||
private ?Entity $entity = null;
|
||||
|
||||
|
||||
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainRole::class)]
|
||||
#[Groups(['nameserver-entity:entity', 'nameserver-entity:nameserver'])]
|
||||
private array $roles = [];
|
||||
|
||||
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
|
||||
#[Groups(['nameserver-entity:entity', 'nameserver-entity:nameserver'])]
|
||||
private array $status = [];
|
||||
|
||||
public function getNameserver(): ?Nameserver
|
||||
|
||||
Reference in New Issue
Block a user