From ddee6df4bd67fc002b3e83c3ecc1cfeab0a9e6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Wed, 15 Oct 2025 21:24:48 +0200 Subject: [PATCH] refactor: use DQL to get expiration date of a domain name --- src/Controller/WatchListController.php | 13 ++++++++++++- tests/Controller/WatchlistControllerTest.php | 3 +-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Controller/WatchListController.php b/src/Controller/WatchListController.php index 7ddb272..686e021 100644 --- a/src/Controller/WatchListController.php +++ b/src/Controller/WatchListController.php @@ -7,6 +7,7 @@ use App\Entity\DomainEvent; use App\Entity\DomainStatus; use App\Entity\User; use App\Entity\WatchList; +use App\Repository\DomainEventRepository; use App\Repository\WatchListRepository; use Doctrine\Common\Collections\Collection; use Eluceo\iCal\Domain\Entity\Calendar; @@ -27,6 +28,7 @@ class WatchListController extends AbstractController { public function __construct( private readonly WatchListRepository $watchListRepository, + private readonly DomainEventRepository $domainEventRepository, ) { } @@ -108,7 +110,16 @@ class WatchListController extends AbstractController /** @var Domain $domain */ foreach ($watchList->getDomains()->getIterator() as $domain) { /** @var DomainEvent|null $exp */ - $exp = $domain->getEvents()->findFirst(fn (int $key, DomainEvent $e) => !$e->getDeleted() && 'expiration' === $e->getAction()); + $exp = $this->domainEventRepository->createQueryBuilder('de') + ->select() + ->where('de.domain = :domain') + ->andWhere('de.action = \'expiration\'') + ->andWhere('de.deleted = FALSE') + ->setParameter('domain', $domain) + ->orderBy('de.date', 'DESC') + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); if (!$domain->getDeleted() && null !== $exp && !in_array($domain, $domains)) { $domains[] = $domain; diff --git a/tests/Controller/WatchlistControllerTest.php b/tests/Controller/WatchlistControllerTest.php index 9ded2d5..816f5d5 100644 --- a/tests/Controller/WatchlistControllerTest.php +++ b/tests/Controller/WatchlistControllerTest.php @@ -34,9 +34,8 @@ final class WatchlistControllerTest extends ApiTestCase public function testGetTrackedDomains() { $client = WatchListUpdateProcessorTest::createUserAndWatchlist(); - - $client->getContainer()->get('doctrine')->getManager()->clear(); $response = $client->request('GET', '/api/tracked'); + $this->assertResponseIsSuccessful(); $data = $response->toArray();