mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 15:23:12 +08:00
Added redirects to the list of domains
This commit is contained in:
@@ -28,6 +28,11 @@ final class NotFoundRedirects implements JsonSerializable
|
||||
return new self(null, null, null);
|
||||
}
|
||||
|
||||
public static function fromConfig(NotFoundRedirectConfigInterface $config): self
|
||||
{
|
||||
return new self($config->baseUrlRedirect(), $config->regular404Redirect(), $config->invalidShortUrlRedirect());
|
||||
}
|
||||
|
||||
public function baseUrlRedirect(): ?string
|
||||
{
|
||||
return $this->baseUrlRedirect;
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Core\Domain\Model;
|
||||
|
||||
use JsonSerializable;
|
||||
use Shlinkio\Shlink\Core\Config\NotFoundRedirectConfigInterface;
|
||||
use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
|
||||
use Shlinkio\Shlink\Core\Entity\Domain;
|
||||
|
||||
final class DomainItem implements JsonSerializable
|
||||
@@ -32,6 +33,7 @@ final class DomainItem implements JsonSerializable
|
||||
return [
|
||||
'domain' => $this->authority,
|
||||
'isDefault' => $this->isDefault,
|
||||
'redirects' => NotFoundRedirects::fromConfig($this->notFoundRedirectConfig),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink\Core\Domain\Repository;
|
||||
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository;
|
||||
use Happyr\DoctrineSpecification\Spec;
|
||||
use Shlinkio\Shlink\Core\Domain\Spec\IsDomain;
|
||||
|
||||
@@ -25,8 +25,6 @@ class ListDomainsAction extends AbstractRestAction
|
||||
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
|
||||
$domainItems = $this->domainService->listDomains($apiKey);
|
||||
|
||||
// TODO Support including not found redirects if requested via query param
|
||||
|
||||
return new JsonResponse([
|
||||
'domains' => [
|
||||
'data' => $domainItems,
|
||||
|
||||
@@ -31,30 +31,60 @@ class ListDomainsTest extends ApiTestCase
|
||||
[
|
||||
'domain' => 'doma.in',
|
||||
'isDefault' => true,
|
||||
'redirects' => [
|
||||
'baseUrlRedirect' => null,
|
||||
'regular404Redirect' => null,
|
||||
'invalidShortUrlRedirect' => null,
|
||||
],
|
||||
],
|
||||
[
|
||||
'domain' => 'detached-with-redirects.com',
|
||||
'isDefault' => false,
|
||||
'redirects' => [
|
||||
'baseUrlRedirect' => 'foo.com',
|
||||
'regular404Redirect' => 'bar.com',
|
||||
'invalidShortUrlRedirect' => null,
|
||||
],
|
||||
],
|
||||
[
|
||||
'domain' => 'example.com',
|
||||
'isDefault' => false,
|
||||
'redirects' => [
|
||||
'baseUrlRedirect' => null,
|
||||
'regular404Redirect' => null,
|
||||
'invalidShortUrlRedirect' => null,
|
||||
],
|
||||
],
|
||||
[
|
||||
'domain' => 'some-domain.com',
|
||||
'isDefault' => false,
|
||||
'redirects' => [
|
||||
'baseUrlRedirect' => null,
|
||||
'regular404Redirect' => null,
|
||||
'invalidShortUrlRedirect' => null,
|
||||
],
|
||||
],
|
||||
]];
|
||||
yield 'author API key' => ['author_api_key', [
|
||||
[
|
||||
'domain' => 'doma.in',
|
||||
'isDefault' => true,
|
||||
'redirects' => [
|
||||
'baseUrlRedirect' => null,
|
||||
'regular404Redirect' => null,
|
||||
'invalidShortUrlRedirect' => null,
|
||||
],
|
||||
],
|
||||
]];
|
||||
yield 'domain API key' => ['domain_api_key', [
|
||||
[
|
||||
'domain' => 'example.com',
|
||||
'isDefault' => false,
|
||||
'redirects' => [
|
||||
'baseUrlRedirect' => null,
|
||||
'regular404Redirect' => null,
|
||||
'invalidShortUrlRedirect' => null,
|
||||
],
|
||||
],
|
||||
]];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user