Updated short URL edition so that it supports editing tags

This commit is contained in:
Alejandro Celaya
2021-01-31 12:12:21 +01:00
parent c58fa586e1
commit 977058d219
5 changed files with 41 additions and 5 deletions

View File

@@ -138,8 +138,10 @@ class ShortUrl extends AbstractEntity
return $this;
}
public function update(ShortUrlEdit $shortUrlEdit): void
{
public function update(
ShortUrlEdit $shortUrlEdit,
?ShortUrlRelationResolverInterface $relationResolver = null
): void {
if ($shortUrlEdit->hasValidSince()) {
$this->validSince = $shortUrlEdit->validSince();
}
@@ -152,6 +154,10 @@ class ShortUrl extends AbstractEntity
if ($shortUrlEdit->hasLongUrl()) {
$this->longUrl = $shortUrlEdit->longUrl();
}
if ($shortUrlEdit->hasTags()) {
$relationResolver = $relationResolver ?? new SimpleShortUrlRelationResolver();
$this->tags = $relationResolver->resolveTags($shortUrlEdit->tags());
}
}
/**

View File

@@ -15,6 +15,7 @@ use Shlinkio\Shlink\Core\Model\ShortUrlsParams;
use Shlinkio\Shlink\Core\Paginator\Adapter\ShortUrlRepositoryAdapter;
use Shlinkio\Shlink\Core\Repository\ShortUrlRepository;
use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface;
use Shlinkio\Shlink\Core\ShortUrl\Resolver\ShortUrlRelationResolverInterface;
use Shlinkio\Shlink\Core\Util\TagManagerTrait;
use Shlinkio\Shlink\Core\Util\UrlValidatorInterface;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
@@ -26,15 +27,18 @@ class ShortUrlService implements ShortUrlServiceInterface
private ORM\EntityManagerInterface $em;
private ShortUrlResolverInterface $urlResolver;
private UrlValidatorInterface $urlValidator;
private ShortUrlRelationResolverInterface $relationResolver;
public function __construct(
ORM\EntityManagerInterface $em,
ShortUrlResolverInterface $urlResolver,
UrlValidatorInterface $urlValidator
UrlValidatorInterface $urlValidator,
ShortUrlRelationResolverInterface $relationResolver
) {
$this->em = $em;
$this->urlResolver = $urlResolver;
$this->urlValidator = $urlValidator;
$this->relationResolver = $relationResolver;
}
/**
@@ -80,7 +84,7 @@ class ShortUrlService implements ShortUrlServiceInterface
}
$shortUrl = $this->urlResolver->resolveShortUrl($identifier, $apiKey);
$shortUrl->update($shortUrlEdit);
$shortUrl->update($shortUrlEdit, $this->relationResolver);
$this->em->flush();