Created rest endpoint to list existing domains

This commit is contained in:
Alejandro Celaya
2020-09-27 09:53:12 +02:00
parent 8109ceb7eb
commit 76d6d9a7a9
11 changed files with 239 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Domain;
use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepositoryInterface;
use Shlinkio\Shlink\Core\Entity\Domain;
class DomainService implements DomainServiceInterface
{
private EntityManagerInterface $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* @return Domain[]
*/
public function listDomainsWithout(?string $excludeDomain = null): array
{
/** @var DomainRepositoryInterface $repo */
$repo = $this->em->getRepository(Domain::class);
return $repo->findDomainsWithout($excludeDomain);
}
}

View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Domain;
use Shlinkio\Shlink\Core\Entity\Domain;
interface DomainServiceInterface
{
/**
* @return Domain[]
*/
public function listDomainsWithout(?string $excludeDomain = null): array;
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Domain\Repository;
use Doctrine\ORM\EntityRepository;
use Shlinkio\Shlink\Core\Entity\Domain;
class DomainRepository extends EntityRepository implements DomainRepositoryInterface
{
/**
* @return Domain[]
*/
public function findDomainsWithout(?string $excludedAuthority = null): array
{
$qb = $this->createQueryBuilder('d')->orderBy('d.authority', 'ASC');
if ($excludedAuthority !== null) {
$qb->where($qb->expr()->neq('d.authority', ':excludedAuthority'))
->setParameter('excludedAuthority', $excludedAuthority);
}
return $qb->getQuery()->getResult();
}
}

View File

@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Domain\Repository;
use Doctrine\Persistence\ObjectRepository;
use Shlinkio\Shlink\Core\Entity\Domain;
interface DomainRepositoryInterface extends ObjectRepository
{
/**
* @return Domain[]
*/
public function findDomainsWithout(?string $excludedAuthority = null): array;
}