Added redirects to the list of domains

This commit is contained in:
Alejandro Celaya 2021-08-03 17:00:26 +02:00
parent 7b43403b1c
commit 565fe4c348
6 changed files with 60 additions and 8 deletions

View File

@ -18,7 +18,7 @@
],
"responses": {
"200": {
"description": "The list of tags",
"description": "The list of domains",
"content": {
"application/json": {
"schema": {
@ -33,13 +33,16 @@
"type": "array",
"items": {
"type": "object",
"required": ["domain", "isDefault"],
"required": ["domain", "isDefault", "redirects"],
"properties": {
"domain": {
"type": "string"
},
"isDefault": {
"type": "boolean"
},
"redirects": {
"$ref": "../definitions/NotFoundRedirects.json"
}
}
}
@ -56,15 +59,30 @@
"data": [
{
"domain": "example.com",
"isDefault": true
"isDefault": true,
"redirects": {
"baseUrlRedirect": "https://example.com/my-landing-page",
"regular404Redirect": null,
"invalidShortUrlRedirect": "https://example.com/invalid-url"
}
},
{
"domain": "aaa.com",
"isDefault": false
"isDefault": false,
"redirects": {
"baseUrlRedirect": null,
"regular404Redirect": null,
"invalidShortUrlRedirect": null
}
},
{
"domain": "bbb.com",
"isDefault": false
"isDefault": false,
"redirects": {
"baseUrlRedirect": null,
"regular404Redirect": null,
"invalidShortUrlRedirect": "https://example.com/invalid-url"
}
}
]
}

View File

@ -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;

View File

@ -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),
];
}

View File

@ -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;

View File

@ -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,

View File

@ -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,
],
],
]];
}