mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Added option to set tags while creating short code from rest API
This commit is contained in:
parent
322180bde4
commit
b6fee0ebaf
@ -66,9 +66,10 @@ class CreateShortcodeAction extends AbstractRestAction
|
|||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
$longUrl = $postData['longUrl'];
|
$longUrl = $postData['longUrl'];
|
||||||
|
$tags = isset($postData['tags']) && is_array($postData['tags']) ? $postData['tags'] : [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$shortCode = $this->urlShortener->urlToShortCode(new Uri($longUrl));
|
$shortCode = $this->urlShortener->urlToShortCode(new Uri($longUrl), $tags);
|
||||||
$shortUrl = (new Uri())->withPath($shortCode)
|
$shortUrl = (new Uri())->withPath($shortCode)
|
||||||
->withScheme($this->domainConfig['schema'])
|
->withScheme($this->domainConfig['schema'])
|
||||||
->withHost($this->domainConfig['hostname']);
|
->withHost($this->domainConfig['hostname']);
|
||||||
|
@ -47,7 +47,8 @@ class CreateShortcodeActionTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function properShortcodeConversionReturnsData()
|
public function properShortcodeConversionReturnsData()
|
||||||
{
|
{
|
||||||
$this->urlShortener->urlToShortCode(Argument::type(Uri::class))->willReturn('abc123')
|
$this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'))
|
||||||
|
->willReturn('abc123')
|
||||||
->shouldBeCalledTimes(1);
|
->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
|
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
|
||||||
@ -63,7 +64,8 @@ class CreateShortcodeActionTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function anInvalidUrlReturnsError()
|
public function anInvalidUrlReturnsError()
|
||||||
{
|
{
|
||||||
$this->urlShortener->urlToShortCode(Argument::type(Uri::class))->willThrow(InvalidUrlException::class)
|
$this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'))
|
||||||
|
->willThrow(InvalidUrlException::class)
|
||||||
->shouldBeCalledTimes(1);
|
->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
|
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
|
||||||
@ -79,7 +81,8 @@ class CreateShortcodeActionTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function aGenericExceptionWillReturnError()
|
public function aGenericExceptionWillReturnError()
|
||||||
{
|
{
|
||||||
$this->urlShortener->urlToShortCode(Argument::type(Uri::class))->willThrow(\Exception::class)
|
$this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'))
|
||||||
|
->willThrow(\Exception::class)
|
||||||
->shouldBeCalledTimes(1);
|
->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
|
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
|
||||||
|
Loading…
Reference in New Issue
Block a user