diff --git a/src/Api/Extension/NotNullAccreditationIanaExtension.php b/src/Api/Extension/NotNullAccreditationIanaExtension.php new file mode 100644 index 0000000..2ef74d5 --- /dev/null +++ b/src/Api/Extension/NotNullAccreditationIanaExtension.php @@ -0,0 +1,28 @@ +getName()) { + $rootAlias = $queryBuilder->getRootAliases()[0]; + $queryBuilder->andWhere(sprintf('%s.ianaAccreditation.status IS NOT NULL', $rootAlias)); + } + } +} diff --git a/src/Entity/Entity.php b/src/Entity/Entity.php index de6fcc9..6da05f4 100644 --- a/src/Entity/Entity.php +++ b/src/Entity/Entity.php @@ -2,7 +2,10 @@ namespace App\Entity; +use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; +use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\GetCollection; use App\Repository\EntityRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; @@ -17,6 +20,31 @@ use Symfony\Component\Serializer\Attribute\SerializedName; )] #[ApiResource( operations: [ + new GetCollection( + uriTemplate: '/entities/iana-accreditations', + openapiContext: [ + 'parameters' => [ + [ + 'name' => 'ianaAccreditation.status', + 'in' => 'query', + 'required' => true, + 'schema' => [ + 'type' => 'array', + 'items' => [ + 'type' => 'string', + 'enum' => ['Accredited', 'Terminated', 'Reserved'], + ], + ], + 'style' => 'form', + 'explode' => true, + 'description' => 'Filter by IANA accreditation status', + ], + ], + ], + description: 'IANA Registrar IDs list', + normalizationContext: ['groups' => ['entity:list']], + name: 'iana_accreditations_collection' + ), /* new GetCollection( uriTemplate: '/entities', @@ -39,6 +67,12 @@ use Symfony\Component\Serializer\Attribute\SerializedName; */ ] )] +#[ApiFilter( + SearchFilter::class, + properties: [ + 'ianaAccreditation.status' => 'exact', + ] +)] class Entity { #[ORM\Id] @@ -75,7 +109,7 @@ class Entity * @var Collection */ #[ORM\OneToMany(targetEntity: EntityEvent::class, mappedBy: 'entity', cascade: ['persist'], orphanRemoval: true)] - #[Groups(['entity:list', 'entity:item', 'entity:list', 'domain:item'])] + #[Groups(['entity:item', 'domain:item'])] private Collection $events; #[ORM\Column] @@ -87,8 +121,8 @@ class Entity private ?array $remarks = null; #[Embedded(class: IanaAccreditation::class, columnPrefix: 'iana_')] - #[Groups(['entity:item', 'domain:item'])] - private IanaAccreditation $ianaAccreditation; + #[Groups(['entity:list', 'entity:item', 'domain:item'])] + private ?IanaAccreditation $ianaAccreditation = null; public function __construct() { @@ -248,12 +282,12 @@ class Entity return $this; } - public function getIanaAccreditation(): IanaAccreditation + public function getIanaAccreditation(): ?IanaAccreditation { - return $this->ianaAccreditation; + return null === $this->ianaAccreditation->getStatus() ? null : $this->ianaAccreditation; } - public function setIanaAccreditation(IanaAccreditation $ianaAccreditation): void + public function setIanaAccreditation(?IanaAccreditation $ianaAccreditation): void { $this->ianaAccreditation = $ianaAccreditation; } diff --git a/src/Entity/IanaAccreditation.php b/src/Entity/IanaAccreditation.php index 72928f1..c8a61d2 100644 --- a/src/Entity/IanaAccreditation.php +++ b/src/Entity/IanaAccreditation.php @@ -12,7 +12,7 @@ use Symfony\Component\Serializer\Attribute\Groups; class IanaAccreditation { #[ORM\Column(length: 255, nullable: true)] - #[Groups(['entity:item', 'domain:item'])] + #[Groups(['entity:item', 'entity:list', 'domain:item'])] private ?string $registrarName = null; #[ORM\Column(length: 255, nullable: true)] @@ -20,7 +20,7 @@ class IanaAccreditation private ?string $rdapBaseUrl = null; #[ORM\Column(nullable: true, enumType: RegistrarStatus::class)] - #[Groups(['entity:item', 'domain:item'])] + #[Groups(['entity:item', 'entity:list', 'domain:item'])] private ?RegistrarStatus $status = null; #[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)] diff --git a/src/Entity/WatchListTrigger.php b/src/Entity/WatchListTrigger.php index d10b8c8..eb23d50 100644 --- a/src/Entity/WatchListTrigger.php +++ b/src/Entity/WatchListTrigger.php @@ -16,6 +16,7 @@ use Symfony\Component\Serializer\Attribute\Groups; #[ORM\Entity(repositoryClass: EventTriggerRepository::class)] #[ApiResource( uriTemplate: '/watchlists/{watchListId}/triggers/{action}/{event}', + shortName: 'Watchlist Trigger', operations: [ new Get(), new GetCollection(