mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-18 02:05:36 +00:00
feat: merging the domain refresh endpoint with the GET endpoint
This commit is contained in:
parent
00a58b2447
commit
0b4f3fb2b3
@ -2,18 +2,34 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Domain;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Service\RDAPService;
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class DomainRefreshController extends AbstractController
|
||||
{
|
||||
|
||||
public function __construct(private readonly DomainRepository $domainRepository,
|
||||
private readonly RDAPService $RDAPService)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @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(
|
||||
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: [
|
||||
'groups' => [
|
||||
'domain:item',
|
||||
@ -39,18 +40,8 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
'nameserver-entity:entity',
|
||||
'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
|
||||
*/
|
||||
private function registerDomain(string $fqdn): void
|
||||
public function registerDomain(string $fqdn): Domain
|
||||
{
|
||||
$idnDomain = idn_to_ascii($fqdn);
|
||||
$tld = $this->getTld($idnDomain);
|
||||
@ -178,6 +178,7 @@ readonly class RDAPService
|
||||
$this->em->persist($domain);
|
||||
$this->em->flush();
|
||||
|
||||
return $domain;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user