mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 09:43:13 +08:00
Refactored UrlShortener public method to receibe DTOs instead of primitive params
This commit is contained in:
@@ -53,17 +53,9 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
|
||||
|
||||
$longUrl = $shortUrlData->getLongUrl();
|
||||
$shortUrlMeta = $shortUrlData->getMeta();
|
||||
$customSlug = $shortUrlMeta->getCustomSlug();
|
||||
|
||||
try {
|
||||
$shortUrl = $this->urlShortener->urlToShortCode(
|
||||
$longUrl,
|
||||
$shortUrlData->getTags(),
|
||||
$shortUrlMeta->getValidSince(),
|
||||
$shortUrlMeta->getValidUntil(),
|
||||
$customSlug,
|
||||
$shortUrlMeta->getMaxVisits()
|
||||
);
|
||||
$shortUrl = $this->urlShortener->urlToShortCode($longUrl, $shortUrlData->getTags(), $shortUrlMeta);
|
||||
$transformer = new ShortUrlDataTransformer($this->domainConfig);
|
||||
|
||||
return new JsonResponse($transformer->transform($shortUrl));
|
||||
@@ -74,6 +66,7 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
|
||||
'message' => sprintf('Provided URL %s is invalid. Try with a different one.', $longUrl),
|
||||
], self::STATUS_BAD_REQUEST);
|
||||
} catch (NonUniqueSlugException $e) {
|
||||
$customSlug = $shortUrlMeta->getCustomSlug();
|
||||
$this->logger->warning('Provided non-unique slug. {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::getRestErrorCodeFromException($e),
|
||||
|
||||
Reference in New Issue
Block a user