From 597c744161e20e7ad69af53267e57919d81edd39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Wed, 22 Oct 2025 16:16:27 +0200 Subject: [PATCH] refactor: move DQL in repositories --- src/Repository/DomainStatusRepository.php | 14 +++++++++++++- src/Service/RDAPService.php | 12 +++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Repository/DomainStatusRepository.php b/src/Repository/DomainStatusRepository.php index a43a95b..018e5e1 100644 --- a/src/Repository/DomainStatusRepository.php +++ b/src/Repository/DomainStatusRepository.php @@ -17,7 +17,7 @@ class DomainStatusRepository extends ServiceEntityRepository parent::__construct($registry, DomainStatus::class); } - public function findNewDomainStatus(Domain $domain, \DateTimeImmutable $updatedAt) + public function findNewDomainStatus(Domain $domain, \DateTimeImmutable $updatedAt): ?DomainStatus { return $this->createQueryBuilder('ds') ->select() @@ -30,6 +30,18 @@ class DomainStatusRepository extends ServiceEntityRepository ->getOneOrNullResult(); } + public function findLastDomainStatus(Domain $domain): ?DomainStatus + { + return $this->createQueryBuilder('ds') + ->select() + ->where('ds.domain = :domain') + ->setParameter('domain', $domain) + ->orderBy('ds.createdAt', 'DESC') + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); + } + // /** // * @return DomainStatus[] Returns an array of DomainStatus objects // */ diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index 9604cf5..62a804a 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -80,7 +80,8 @@ class RDAPService private readonly StatService $statService, private readonly InfluxdbService $influxService, #[Autowire(param: 'influxdb_enabled')] - private readonly bool $influxdbEnabled, private readonly DomainStatusRepository $domainStatusRepository, + private readonly bool $influxdbEnabled, + private readonly DomainStatusRepository $domainStatusRepository, ) { } @@ -721,14 +722,7 @@ class RDAPService private function calculateDaysFromStatus(Domain $domain, \DateTimeImmutable $now): ?int { /** @var ?DomainStatus $lastStatus */ - $lastStatus = $this->domainStatusRepository->createQueryBuilder('ds') - ->select() - ->where('ds.domain = :domain') - ->setParameter('domain', $domain) - ->orderBy('ds.createdAt', 'DESC') - ->setMaxResults(1) - ->getQuery() - ->getOneOrNullResult(); + $lastStatus = $this->domainStatusRepository->findLastDomainStatus($domain); if (null === $lastStatus) { return null;