Deprecated action and endpoint to edit short URL tags

This commit is contained in:
Alejandro Celaya
2021-01-31 12:24:26 +01:00
parent 977058d219
commit cdfd14e63f
7 changed files with 18 additions and 51 deletions
@@ -8,11 +8,14 @@ use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Core\Exception\ValidationException;
use Shlinkio\Shlink\Core\Model\ShortUrlEdit;
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
use Shlinkio\Shlink\Core\Validation\ShortUrlInputFilter;
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware;
/** @deprecated */
class EditShortUrlTagsAction extends AbstractRestAction
{
protected const ROUTE_PATH = '/short-urls/{shortCode}/tags';
@@ -38,7 +41,9 @@ class EditShortUrlTagsAction extends AbstractRestAction
$identifier = ShortUrlIdentifier::fromApiRequest($request);
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
$shortUrl = $this->shortUrlService->setTagsByShortCode($identifier, $tags, $apiKey);
$shortUrl = $this->shortUrlService->updateShortUrl($identifier, ShortUrlEdit::fromRawData([
ShortUrlInputFilter::TAGS => $tags,
]), $apiKey);
return new JsonResponse(['tags' => $shortUrl->getTags()->toArray()]);
}
}
@@ -12,6 +12,7 @@ use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ServerRequestInterface;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\ValidationException;
use Shlinkio\Shlink\Core\Model\ShortUrlEdit;
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlTagsAction;
@@ -41,9 +42,9 @@ class EditShortUrlTagsActionTest extends TestCase
public function tagsListIsReturnedIfCorrectShortCodeIsProvided(): void
{
$shortCode = 'abc123';
$this->shortUrlService->setTagsByShortCode(
$this->shortUrlService->updateShortUrl(
new ShortUrlIdentifier($shortCode),
[],
Argument::type(ShortUrlEdit::class),
Argument::type(ApiKey::class),
)->willReturn(ShortUrl::createEmpty())
->shouldBeCalledOnce();