feat: update API endpoints

This commit is contained in:
Maël Gangloff 2024-07-17 14:00:46 +02:00
parent 36a76f2876
commit c9b9cdad59
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
6 changed files with 25 additions and 56 deletions

View File

@ -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;
/**

View File

@ -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')]

View File

@ -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<int, EntityEvent>
*/
#[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]

View File

@ -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
{

View File

@ -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;

View File

@ -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<int, NameserverEntity>
*/
#[ORM\OneToMany(targetEntity: NameserverEntity::class, mappedBy: 'nameserver', cascade: ['persist'], orphanRemoval: true)]
#[Groups(['nameserver:item'])]
private Collection $nameserverEntities;
/**