feat: merging the domain refresh endpoint with the GET endpoint

This commit is contained in:
Maël Gangloff
2024-07-20 09:45:13 +02:00
parent 00a58b2447
commit 0b4f3fb2b3
3 changed files with 22 additions and 14 deletions

View File

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