mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-25 16:31:16 -06:00
Refactored TagInfo to wrap the raw tag name instead of a Tag entity
This commit is contained in:
parent
dd6bcd68cc
commit
8adb6596fb
@ -46,8 +46,7 @@ class ListTagsCommand extends Command
|
||||
|
||||
return map(
|
||||
$tags,
|
||||
static fn (TagInfo $tagInfo) =>
|
||||
[$tagInfo->tag()->__toString(), $tagInfo->shortUrlsCount(), $tagInfo->visitsCount()],
|
||||
static fn (TagInfo $tagInfo) => [$tagInfo->tag(), $tagInfo->shortUrlsCount(), $tagInfo->visitsCount()],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\CLI\Command\Tag\ListTagsCommand;
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||
use Shlinkio\Shlink\Core\Tag\Model\TagInfo;
|
||||
use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
|
||||
use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
|
||||
@ -45,8 +44,8 @@ class ListTagsCommandTest extends TestCase
|
||||
public function listOfTagsIsPrinted(): void
|
||||
{
|
||||
$tagsInfo = $this->tagService->tagsInfo(Argument::any())->willReturn(new Paginator(new ArrayAdapter([
|
||||
new TagInfo(new Tag('foo'), 10, 2),
|
||||
new TagInfo(new Tag('bar'), 7, 32),
|
||||
new TagInfo('foo', 10, 2),
|
||||
new TagInfo('bar', 7, 32),
|
||||
])));
|
||||
|
||||
$this->commandTester->execute([]);
|
||||
|
@ -108,13 +108,13 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
|
||||
$nativeQb->addOrderBy('t.name_1', $orderMainQuery || $orderDir === null ? 'ASC' : $orderDir);
|
||||
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata(Tag::class, 't');
|
||||
$rsm->addScalarResult('name', 'tag');
|
||||
$rsm->addScalarResult('short_urls_count', 'shortUrlsCount');
|
||||
$rsm->addScalarResult('visits_count', 'visitsCount');
|
||||
|
||||
return map(
|
||||
$this->getEntityManager()->createNativeQuery($nativeQb->getSQL(), $rsm)->getResult(),
|
||||
static fn (array $row) => new TagInfo($row[0], (int) $row['shortUrlsCount'], (int) $row['visitsCount']),
|
||||
static fn (array $row) => new TagInfo($row['tag'], (int) $row['shortUrlsCount'], (int) $row['visitsCount']),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -5,15 +5,14 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink\Core\Tag\Model;
|
||||
|
||||
use JsonSerializable;
|
||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||
|
||||
final class TagInfo implements JsonSerializable
|
||||
{
|
||||
public function __construct(private Tag $tag, private int $shortUrlsCount, private int $visitsCount)
|
||||
public function __construct(private string $tag, private int $shortUrlsCount, private int $visitsCount)
|
||||
{
|
||||
}
|
||||
|
||||
public function tag(): Tag
|
||||
public function tag(): string
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ class TagRepositoryTest extends DatabaseTestCase
|
||||
foreach ($expectedList as $index => [$tag, $shortUrlsCount, $visitsCount]) {
|
||||
self::assertEquals($shortUrlsCount, $result[$index]->shortUrlsCount());
|
||||
self::assertEquals($visitsCount, $result[$index]->visitsCount());
|
||||
self::assertEquals($tag, $result[$index]->tag()->__toString());
|
||||
self::assertEquals($tag, $result[$index]->tag());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class TagServiceTest extends TestCase
|
||||
TagsListFiltering $expectedFiltering,
|
||||
int $countCalls,
|
||||
): void {
|
||||
$expected = [new TagInfo(new Tag('foo'), 1, 1), new TagInfo(new Tag('bar'), 3, 10)];
|
||||
$expected = [new TagInfo('foo', 1, 1), new TagInfo('bar', 3, 10)];
|
||||
|
||||
$find = $this->repo->findTagsWithInfo($expectedFiltering)->willReturn($expected);
|
||||
$count = $this->repo->matchSingleScalarResult(Argument::cetera())->willReturn(2);
|
||||
|
@ -41,7 +41,7 @@ class ListTagsAction extends AbstractRestAction
|
||||
// This part is deprecated. To get tags with stats, the /tags/stats endpoint should be used instead
|
||||
$tagsInfo = $this->tagService->tagsInfo($params, $apiKey);
|
||||
$rawTags = $this->serializePaginator($tagsInfo, null, 'stats');
|
||||
$rawTags['data'] = map($tagsInfo, static fn (TagInfo $info) => $info->tag()->__toString());
|
||||
$rawTags['data'] = map($tagsInfo, static fn (TagInfo $info) => $info->tag());
|
||||
|
||||
return new JsonResponse(['tags' => $rawTags]);
|
||||
}
|
||||
|
@ -76,8 +76,8 @@ class ListTagsActionTest extends TestCase
|
||||
public function returnsStatsWhenRequested(): void
|
||||
{
|
||||
$stats = [
|
||||
new TagInfo(new Tag('foo'), 1, 1),
|
||||
new TagInfo(new Tag('bar'), 3, 10),
|
||||
new TagInfo('foo', 1, 1),
|
||||
new TagInfo('bar', 3, 10),
|
||||
];
|
||||
$itemsCount = count($stats);
|
||||
$tagsInfo = $this->tagService->tagsInfo(Argument::any(), Argument::type(ApiKey::class))->willReturn(
|
||||
|
@ -13,7 +13,6 @@ use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||
use Shlinkio\Shlink\Core\Tag\Model\TagInfo;
|
||||
use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\Tag\TagsStatsAction;
|
||||
@ -38,8 +37,8 @@ class TagsStatsActionTest extends TestCase
|
||||
public function returnsTagsStatsWhenRequested(): void
|
||||
{
|
||||
$stats = [
|
||||
new TagInfo(new Tag('foo'), 1, 1),
|
||||
new TagInfo(new Tag('bar'), 3, 10),
|
||||
new TagInfo('foo', 1, 1),
|
||||
new TagInfo('bar', 3, 10),
|
||||
];
|
||||
$itemsCount = count($stats);
|
||||
$tagsInfo = $this->tagService->tagsInfo(Argument::any(), Argument::type(ApiKey::class))->willReturn(
|
||||
|
Loading…
Reference in New Issue
Block a user