diff --git a/src/Entity/Domain.php b/src/Entity/Domain.php index f392746..dfe4f46 100644 --- a/src/Entity/Domain.php +++ b/src/Entity/Domain.php @@ -4,6 +4,7 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\GetCollection; use App\Repository\DomainRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; @@ -16,16 +17,26 @@ use Symfony\Component\Serializer\Attribute\Groups; #[UniqueEntity('handle')] #[ApiResource( operations: [ + new GetCollection( + uriTemplate: '/domains', + normalizationContext: [ + 'groups' => [ + 'domain:list' + ] + ] + ), new Get( uriTemplate: '/domains/{ldhName}', - normalizationContext: ['groups' => [ - 'domain:item', - 'event:list', - 'entity:list', - 'domain-entity:entity', - 'nameserver-entity:nameserver', - 'nameserver:item', - ]] + normalizationContext: [ + 'groups' => [ + 'domain:item', + 'event:list', + 'entity:list', + 'domain-entity:entity', + 'nameserver-entity:nameserver', + 'nameserver:item', + ] + ] ) ] )] @@ -33,11 +44,11 @@ class Domain { #[ORM\Id] #[ORM\Column(length: 255)] - #[Groups(['domain:item'])] + #[Groups(['domain:item', 'domain:list'])] private ?string $ldhName = null; #[ORM\Column(length: 255)] - #[Groups(['domain:item'])] + #[Groups(['domain:item', 'domain:list'])] private ?string $handle = null; /** diff --git a/src/Entity/DomainEvent.php b/src/Entity/DomainEvent.php index f55814f..7dfe1f0 100644 --- a/src/Entity/DomainEvent.php +++ b/src/Entity/DomainEvent.php @@ -2,22 +2,10 @@ 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')] diff --git a/src/Entity/Entity.php b/src/Entity/Entity.php index 5b57dae..25c7462 100644 --- a/src/Entity/Entity.php +++ b/src/Entity/Entity.php @@ -2,6 +2,8 @@ namespace App\Entity; +use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; +use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; @@ -12,6 +14,7 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Attribute\Groups; #[ORM\Entity(repositoryClass: EntityRepository::class)] +#[ApiFilter(SearchFilter::class, properties: ['jCard' => 'partial'])] #[ApiResource( operations: [ new GetCollection( @@ -58,7 +61,7 @@ class Entity * @var Collection */ #[ORM\OneToMany(targetEntity: EntityEvent::class, mappedBy: 'entity', cascade: ['persist'], orphanRemoval: true)] - #[Groups(['entity:list', 'entity:item'])] + #[Groups(['entity:list', 'entity:item', 'entity:list'])] private Collection $events; #[ORM\Column] diff --git a/src/Entity/EntityEvent.php b/src/Entity/EntityEvent.php index 260d98e..21bf1d3 100644 --- a/src/Entity/EntityEvent.php +++ b/src/Entity/EntityEvent.php @@ -2,24 +2,10 @@ 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 { diff --git a/src/Entity/Event.php b/src/Entity/Event.php index 17f1fd9..a8ce6e3 100644 --- a/src/Entity/Event.php +++ b/src/Entity/Event.php @@ -2,8 +2,6 @@ namespace App\Entity; -use ApiPlatform\Metadata\ApiResource; -use ApiPlatform\Metadata\Get; use App\Config\EventAction; use DateTimeImmutable; use Doctrine\ORM\Mapping as ORM; diff --git a/src/Entity/Nameserver.php b/src/Entity/Nameserver.php index 11bab92..fa4e666 100644 --- a/src/Entity/Nameserver.php +++ b/src/Entity/Nameserver.php @@ -2,8 +2,6 @@ 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; @@ -11,20 +9,6 @@ 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 { @@ -37,7 +21,6 @@ class Nameserver * @var Collection */ #[ORM\OneToMany(targetEntity: NameserverEntity::class, mappedBy: 'nameserver', cascade: ['persist'], orphanRemoval: true)] - #[Groups(['nameserver:item'])] private Collection $nameserverEntities; /**