diff options
Diffstat (limited to 'lib/classes/JsonApi/Routes/ShortUrls')
| -rw-r--r-- | lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php b/lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php index db2a856..1b8524a 100644 --- a/lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php +++ b/lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php @@ -2,6 +2,7 @@ namespace JsonApi\Routes\ShortUrls; +use ShortUrl; use JsonApi\Errors\AuthorizationFailedException; use JsonApi\Errors\ConflictException; use JsonApi\JsonApiController; @@ -26,12 +27,14 @@ final class ShortUrlCreate extends JsonApiController $json = $this->validate($request, $args); - if (\ShortUrl::countBySql('path = ? AND user_id = ?', [ $json['data']['attributes']['path'], $user->id]) > 0) { - throw new ConflictException(_('Sie haben für diese Seite bereits eine Kurz-URL erstellt!')); + $short_url = ShortUrl::findOneBySQL('`path` = ? AND `user_id` = ?', [$json['data']['attributes']['path'], $user->id]); + + if ($short_url) { + return $this->getContentResponse($short_url); } if (\ShortUrl::countBySql('alias = ?', [ $json['data']['attributes']['alias']])) { - throw new ConflictException(_('Sie haben für diese Seite bereits eine Kurz-URL erstellt!')); + throw new ConflictException(_('Der verwendete Alias existiert bereits.')); } $short_url = \ShortUrl::create([ |
