refactor: use DQL to get expiration date of a domain name

This commit is contained in:
Maël Gangloff 2025-10-15 21:24:48 +02:00
parent 0c2148d889
commit ddee6df4bd
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
2 changed files with 13 additions and 3 deletions

View File

@ -7,6 +7,7 @@ use App\Entity\DomainEvent;
use App\Entity\DomainStatus; use App\Entity\DomainStatus;
use App\Entity\User; use App\Entity\User;
use App\Entity\WatchList; use App\Entity\WatchList;
use App\Repository\DomainEventRepository;
use App\Repository\WatchListRepository; use App\Repository\WatchListRepository;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Eluceo\iCal\Domain\Entity\Calendar; use Eluceo\iCal\Domain\Entity\Calendar;
@ -27,6 +28,7 @@ class WatchListController extends AbstractController
{ {
public function __construct( public function __construct(
private readonly WatchListRepository $watchListRepository, private readonly WatchListRepository $watchListRepository,
private readonly DomainEventRepository $domainEventRepository,
) { ) {
} }
@ -108,7 +110,16 @@ class WatchListController extends AbstractController
/** @var Domain $domain */ /** @var Domain $domain */
foreach ($watchList->getDomains()->getIterator() as $domain) { foreach ($watchList->getDomains()->getIterator() as $domain) {
/** @var DomainEvent|null $exp */ /** @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)) { if (!$domain->getDeleted() && null !== $exp && !in_array($domain, $domains)) {
$domains[] = $domain; $domains[] = $domain;

View File

@ -34,9 +34,8 @@ final class WatchlistControllerTest extends ApiTestCase
public function testGetTrackedDomains() public function testGetTrackedDomains()
{ {
$client = WatchListUpdateProcessorTest::createUserAndWatchlist(); $client = WatchListUpdateProcessorTest::createUserAndWatchlist();
$client->getContainer()->get('doctrine')->getManager()->clear();
$response = $client->request('GET', '/api/tracked'); $response = $client->request('GET', '/api/tracked');
$this->assertResponseIsSuccessful(); $this->assertResponseIsSuccessful();
$data = $response->toArray(); $data = $response->toArray();