mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Split spec to join ApiKey spec with short URLs, into inlined and regular versions
This commit is contained in:
parent
9e9621e7b2
commit
d0546a2ea2
3 changed files with 31 additions and 9 deletions
|
@ -13,6 +13,7 @@ use Shlinkio\Shlink\Core\Tag\Model\TagsListFiltering;
|
|||
use Shlinkio\Shlink\Core\Tag\Spec\CountTagsWithName;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Role;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Spec\WithApiKeySpecsEnsuringJoin;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Spec\WithInlinedApiKeySpecsEnsuringJoin;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
|
||||
use function Functional\map;
|
||||
|
@ -21,8 +22,6 @@ use const PHP_INT_MAX;
|
|||
|
||||
class TagRepository extends EntitySpecificationRepository implements TagRepositoryInterface
|
||||
{
|
||||
private const PARAM_PLACEHOLDER = '?';
|
||||
|
||||
public function deleteByName(array $names): int
|
||||
{
|
||||
if (empty($names)) {
|
||||
|
@ -54,7 +53,7 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
|
|||
}
|
||||
|
||||
$apiKey = $filtering?->apiKey();
|
||||
$this->applySpecification($subQb, new WithApiKeySpecsEnsuringJoin($apiKey, 'shortUrls', true), 't');
|
||||
$this->applySpecification($subQb, new WithInlinedApiKeySpecsEnsuringJoin($apiKey, 'shortUrls'), 't');
|
||||
|
||||
$subQuery = $subQb->getQuery();
|
||||
$subQuerySql = $subQuery->getSQL();
|
||||
|
|
|
@ -11,11 +11,8 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
|||
|
||||
class WithApiKeySpecsEnsuringJoin extends BaseSpecification
|
||||
{
|
||||
public function __construct(
|
||||
private ?ApiKey $apiKey,
|
||||
private string $fieldToJoin = 'shortUrls',
|
||||
private bool $inlined = false,
|
||||
) {
|
||||
public function __construct(private ?ApiKey $apiKey, private string $fieldToJoin = 'shortUrls')
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -23,7 +20,7 @@ class WithApiKeySpecsEnsuringJoin extends BaseSpecification
|
|||
{
|
||||
return $this->apiKey === null || $this->apiKey->isAdmin() ? Spec::andX() : Spec::andX(
|
||||
Spec::join($this->fieldToJoin, 's'),
|
||||
$this->inlined ? $this->apiKey->inlinedSpec() : $this->apiKey->spec($this->fieldToJoin),
|
||||
$this->apiKey->spec($this->fieldToJoin),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\ApiKey\Spec;
|
||||
|
||||
use Happyr\DoctrineSpecification\Spec;
|
||||
use Happyr\DoctrineSpecification\Specification\BaseSpecification;
|
||||
use Happyr\DoctrineSpecification\Specification\Specification;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
|
||||
class WithInlinedApiKeySpecsEnsuringJoin extends BaseSpecification
|
||||
{
|
||||
public function __construct(private ?ApiKey $apiKey, private string $fieldToJoin = 'shortUrls')
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function getSpec(): Specification
|
||||
{
|
||||
return $this->apiKey === null || $this->apiKey->isAdmin() ? Spec::andX() : Spec::andX(
|
||||
Spec::join($this->fieldToJoin, 's'),
|
||||
$this->apiKey->inlinedSpec(),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue