Return deviceLongUrls as part of the short URL data and document API changes

This commit is contained in:
Alejandro Celaya
2023-01-21 12:05:54 +01:00
parent b1b67c497e
commit 48bd97fe41
12 changed files with 159 additions and 65 deletions

View File

@@ -25,8 +25,10 @@ use Shlinkio\Shlink\Core\Visit\Model\VisitType;
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use function array_fill_keys;
use function count;
use function Functional\map;
use function Shlinkio\Shlink\Core\enumValues;
use function Shlinkio\Shlink\Core\generateRandomShortCode;
use function Shlinkio\Shlink\Core\normalizeDate;
use function Shlinkio\Shlink\Core\normalizeOptionalDate;
@@ -330,7 +332,7 @@ class ShortUrl extends AbstractEntity
public function deviceLongUrls(): array
{
$data = [];
$data = array_fill_keys(enumValues(DeviceType::class), null);
foreach ($this->deviceLongUrls as $deviceUrl) {
$data[$deviceUrl->deviceType->value] = $deviceUrl->longUrl();
}

View File

@@ -27,6 +27,7 @@ class ShortUrlDataTransformer implements DataTransformerInterface
'shortCode' => $shortUrl->getShortCode(),
'shortUrl' => $this->stringifier->stringify($shortUrl),
'longUrl' => $shortUrl->getLongUrl(),
'deviceLongUrls' => $shortUrl->deviceLongUrls(),
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
'tags' => invoke($shortUrl->getTags(), '__toString'),
'meta' => $this->buildMeta($shortUrl),

View File

@@ -52,6 +52,7 @@ class PublishingUpdatesGeneratorTest extends TestCase
'shortCode' => $shortUrl->getShortCode(),
'shortUrl' => 'http:/' . $shortUrl->getShortCode(),
'longUrl' => 'longUrl',
'deviceLongUrls' => $shortUrl->deviceLongUrls(),
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
'visitsCount' => 0,
'tags' => [],
@@ -129,6 +130,7 @@ class PublishingUpdatesGeneratorTest extends TestCase
'shortCode' => $shortUrl->getShortCode(),
'shortUrl' => 'http:/' . $shortUrl->getShortCode(),
'longUrl' => 'longUrl',
'deviceLongUrls' => $shortUrl->deviceLongUrls(),
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
'visitsCount' => 0,
'tags' => [],

View File

@@ -20,6 +20,9 @@ use Shlinkio\Shlink\Core\ShortUrl\ShortUrlService;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use ShlinkioTest\Shlink\Core\Util\ApiKeyHelpersTrait;
use function array_fill_keys;
use function Shlinkio\Shlink\Core\enumValues;
class ShortUrlServiceTest extends TestCase
{
use ApiKeyHelpersTrait;
@@ -74,7 +77,7 @@ class ShortUrlServiceTest extends TestCase
);
$resolveDeviceLongUrls = function () use ($shortUrlEdit): array {
$result = [];
$result = array_fill_keys(enumValues(DeviceType::class), null);
foreach ($shortUrlEdit->deviceLongUrls ?? [] as $longUrl) {
$result[$longUrl->deviceType->value] = $longUrl->longUrl;
}