mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
refactor: merge dql
This commit is contained in:
@@ -5,16 +5,15 @@ namespace App\State;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Repository\EntityRepository;
|
||||
use App\Service\RDAPService;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
readonly class FindDomainCollectionFromEntityProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private RequestStack $requestStack,
|
||||
private EntityRepository $entityRepository,
|
||||
private DomainRepository $domainRepository,
|
||||
) {
|
||||
}
|
||||
@@ -36,30 +35,21 @@ readonly class FindDomainCollectionFromEntityProvider implements ProviderInterfa
|
||||
|
||||
foreach ($forbidden as $word) {
|
||||
if (str_contains(strtolower($registrant), $word)) {
|
||||
throw new HttpException(403, 'Forbidden search term');
|
||||
throw new BadRequestHttpException('Forbidden search term');
|
||||
}
|
||||
}
|
||||
|
||||
$entities = $this->entityRepository->createQueryBuilder('e')
|
||||
->where('e.tld IS NOT NULL')
|
||||
->andWhere('e.handle NOT IN (:blacklist)')
|
||||
->andWhere('UPPER(e.jCardOrg) = UPPER(:registrant) OR UPPER(e.jCardFn) = UPPER(:registrant)')
|
||||
->setParameter('registrant', $registrant)
|
||||
->setParameter('blacklist', RDAPService::ENTITY_HANDLE_BLACKLIST)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
if (empty($entities)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->domainRepository->createQueryBuilder('d')
|
||||
->select('DISTINCT d')
|
||||
->join('d.domainEntities', 'de')
|
||||
->where('de.entity IN (:entityIds)')
|
||||
->andWhere('JSONB_CONTAINS(de.roles, :role) = true')
|
||||
->andWhere('de.deletedAt IS NULL')
|
||||
->setParameter('entityIds', array_map(fn ($e) => $e->getId(), $entities))
|
||||
->join('d.domainEntities', 'de', Join::WITH, 'de.deletedAt IS NULL AND JSONB_CONTAINS(de.roles, :role) = true')
|
||||
->join(
|
||||
'de.entity',
|
||||
'e',
|
||||
Join::WITH,
|
||||
'e.tld IS NOT NULL AND e.handle NOT IN (:blacklist) AND (UPPER(e.jCardOrg) = UPPER(:registrant) OR UPPER(e.jCardFn) = UPPER(:registrant))'
|
||||
)
|
||||
->setParameter('registrant', $registrant)
|
||||
->setParameter('blacklist', RDAPService::ENTITY_HANDLE_BLACKLIST)
|
||||
->setParameter('role', '"registrant"')
|
||||
->getQuery()->getResult();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user