feat: add domain register endpoint

This commit is contained in:
Maël Gangloff
2024-07-17 18:18:11 +02:00
parent 29253a47aa
commit 358cad6c21
4 changed files with 63 additions and 15 deletions

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Controller;
use App\Service\RDAPService;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DomainRefreshController extends AbstractController
{
/**
* @throws Exception
*/
public function __invoke(string $ldhName, RDAPService $RDAPService): void
{
$RDAPService->registerDomains([$ldhName]);
}
}

View File

@@ -28,24 +28,12 @@ class TestController extends AbstractController
{ {
public function __construct( public function __construct(
private readonly RDAPService $RDAPService,
private readonly DomainRepository $domainRepository private readonly DomainRepository $domainRepository
) )
{ {
} }
#[Route(path: '/test/register', name: 'test_register_domain')]
public function testRegisterDomain(Request $request): Response
{
try {
$this->RDAPService->registerDomains(explode(',', $request->query->get('domains')));
} catch (Exception $e) {
return new Response($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
return new Response();
}
#[Route(path: '/test/publish/calendar', name: 'test_publish_calendar')] #[Route(path: '/test/publish/calendar', name: 'test_publish_calendar')]
public function testPublishCalendar(): Response public function testPublishCalendar(): Response
{ {

View File

@@ -5,6 +5,8 @@ namespace App\Entity;
use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use App\Controller\DomainRefreshController;
use App\Repository\DomainRepository; use App\Repository\DomainRepository;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
@@ -33,10 +35,20 @@ use Symfony\Component\Serializer\Attribute\Groups;
'event:list', 'event:list',
'entity:list', 'entity:list',
'domain-entity:entity', 'domain-entity:entity',
'nameserver-entity:nameserver', 'nameserver-entity:nameserver'
'nameserver:item',
] ]
] ]
),
new Post(
uriTemplate: '/domains/{ldhName}',
status: 204,
controller: DomainRefreshController::class,
openapiContext: [
'summary' => 'Request an update of domain name data',
'description' => 'Triggers a refresh of the domain information.',
'requestBody' => false
],
deserialize: false
) )
] ]
)] )]

View File

@@ -2,6 +2,9 @@
namespace App\Entity; namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Repository\NameserverRepository; use App\Repository\NameserverRepository;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
@@ -9,24 +12,50 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups; use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity(repositoryClass: NameserverRepository::class)] #[ORM\Entity(repositoryClass: NameserverRepository::class)]
#[ApiResource(
operations: [
new GetCollection(
uriTemplate: '/nameservers',
normalizationContext: [
'groups' => [
'nameserver:list'
]
]
),
new Get(
uriTemplate: '/nameservers/{ldhName}',
normalizationContext: [
'groups' => [
'nameserver:item',
'domain:list',
'nameserver-entity:entity',
'entity:list',
"event:list"
]
]
)
]
)]
class Nameserver class Nameserver
{ {
#[ORM\Id] #[ORM\Id]
#[ORM\Column(length: 255)] #[ORM\Column(length: 255)]
#[Groups(['nameserver:item'])] #[Groups(['nameserver:item', 'nameserver:list', 'domain:item'])]
private ?string $ldhName = null; private ?string $ldhName = null;
/** /**
* @var Collection<int, NameserverEntity> * @var Collection<int, NameserverEntity>
*/ */
#[ORM\OneToMany(targetEntity: NameserverEntity::class, mappedBy: 'nameserver', cascade: ['persist'], orphanRemoval: true)] #[ORM\OneToMany(targetEntity: NameserverEntity::class, mappedBy: 'nameserver', cascade: ['persist'], orphanRemoval: true)]
#[Groups(['nameserver:item', 'domain:item'])]
private Collection $nameserverEntities; private Collection $nameserverEntities;
/** /**
* @var Collection<int, Domain> * @var Collection<int, Domain>
*/ */
#[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'nameservers')] #[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'nameservers')]
#[Groups(['nameserver:item'])]
private Collection $domains; private Collection $domains;
public function __construct() public function __construct()