mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Refactored TagInfo to wrap the raw tag name instead of a Tag entity
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user