mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: merging the domain refresh endpoint with the GET endpoint
This commit is contained in:
@@ -2,18 +2,34 @@
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Domain;
|
||||||
|
use App\Repository\DomainRepository;
|
||||||
use App\Service\RDAPService;
|
use App\Service\RDAPService;
|
||||||
|
use DateTimeImmutable;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
|
||||||
class DomainRefreshController extends AbstractController
|
class DomainRefreshController extends AbstractController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public function __construct(private readonly DomainRepository $domainRepository,
|
||||||
|
private readonly RDAPService $RDAPService)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function __invoke(string $ldhName, RDAPService $RDAPService): void
|
public function __invoke(string $ldhName,): ?Domain
|
||||||
{
|
{
|
||||||
$RDAPService->registerDomains([$ldhName]);
|
/** @var Domain $domain */
|
||||||
|
$domain = $this->domainRepository->findOneBy(["ldhName" => $ldhName]);
|
||||||
|
if ($domain === null ||
|
||||||
|
$domain->getUpdatedAt()->diff(new DateTimeImmutable('now'))->days >= 7) {
|
||||||
|
|
||||||
|
//TODO : Domain search rate limit here, before the RDAP request
|
||||||
|
$domain = $this->RDAPService->registerDomain($ldhName);
|
||||||
|
}
|
||||||
|
return $domain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
),
|
),
|
||||||
new Get(
|
new Get(
|
||||||
uriTemplate: '/domains/{ldhName}', # Do not delete this line, otherwise Symfony interprets the TLD of the domain name as a return type
|
uriTemplate: '/domains/{ldhName}', # Do not delete this line, otherwise Symfony interprets the TLD of the domain name as a return type
|
||||||
|
controller: DomainRefreshController::class,
|
||||||
normalizationContext: [
|
normalizationContext: [
|
||||||
'groups' => [
|
'groups' => [
|
||||||
'domain:item',
|
'domain:item',
|
||||||
@@ -39,18 +40,8 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
'nameserver-entity:entity',
|
'nameserver-entity:entity',
|
||||||
'tld:item'
|
'tld: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
|
read: false
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)]
|
)]
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ readonly class RDAPService
|
|||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function registerDomain(string $fqdn): void
|
public function registerDomain(string $fqdn): Domain
|
||||||
{
|
{
|
||||||
$idnDomain = idn_to_ascii($fqdn);
|
$idnDomain = idn_to_ascii($fqdn);
|
||||||
$tld = $this->getTld($idnDomain);
|
$tld = $this->getTld($idnDomain);
|
||||||
@@ -178,6 +178,7 @@ readonly class RDAPService
|
|||||||
$this->em->persist($domain);
|
$this->em->persist($domain);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
|
||||||
|
return $domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user