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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user