mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Split spec to join ApiKey spec with short URLs, into inlined and regular versions
This commit is contained in:
parent
9e9621e7b2
commit
d0546a2ea2
@ -13,6 +13,7 @@ use Shlinkio\Shlink\Core\Tag\Model\TagsListFiltering;
|
|||||||
use Shlinkio\Shlink\Core\Tag\Spec\CountTagsWithName;
|
use Shlinkio\Shlink\Core\Tag\Spec\CountTagsWithName;
|
||||||
use Shlinkio\Shlink\Rest\ApiKey\Role;
|
use Shlinkio\Shlink\Rest\ApiKey\Role;
|
||||||
use Shlinkio\Shlink\Rest\ApiKey\Spec\WithApiKeySpecsEnsuringJoin;
|
use Shlinkio\Shlink\Rest\ApiKey\Spec\WithApiKeySpecsEnsuringJoin;
|
||||||
|
use Shlinkio\Shlink\Rest\ApiKey\Spec\WithInlinedApiKeySpecsEnsuringJoin;
|
||||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||||
|
|
||||||
use function Functional\map;
|
use function Functional\map;
|
||||||
@ -21,8 +22,6 @@ use const PHP_INT_MAX;
|
|||||||
|
|
||||||
class TagRepository extends EntitySpecificationRepository implements TagRepositoryInterface
|
class TagRepository extends EntitySpecificationRepository implements TagRepositoryInterface
|
||||||
{
|
{
|
||||||
private const PARAM_PLACEHOLDER = '?';
|
|
||||||
|
|
||||||
public function deleteByName(array $names): int
|
public function deleteByName(array $names): int
|
||||||
{
|
{
|
||||||
if (empty($names)) {
|
if (empty($names)) {
|
||||||
@ -54,7 +53,7 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
|
|||||||
}
|
}
|
||||||
|
|
||||||
$apiKey = $filtering?->apiKey();
|
$apiKey = $filtering?->apiKey();
|
||||||
$this->applySpecification($subQb, new WithApiKeySpecsEnsuringJoin($apiKey, 'shortUrls', true), 't');
|
$this->applySpecification($subQb, new WithInlinedApiKeySpecsEnsuringJoin($apiKey, 'shortUrls'), 't');
|
||||||
|
|
||||||
$subQuery = $subQb->getQuery();
|
$subQuery = $subQb->getQuery();
|
||||||
$subQuerySql = $subQuery->getSQL();
|
$subQuerySql = $subQuery->getSQL();
|
||||||
|
@ -11,11 +11,8 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
|||||||
|
|
||||||
class WithApiKeySpecsEnsuringJoin extends BaseSpecification
|
class WithApiKeySpecsEnsuringJoin extends BaseSpecification
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(private ?ApiKey $apiKey, private string $fieldToJoin = 'shortUrls')
|
||||||
private ?ApiKey $apiKey,
|
{
|
||||||
private string $fieldToJoin = 'shortUrls',
|
|
||||||
private bool $inlined = false,
|
|
||||||
) {
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +20,7 @@ class WithApiKeySpecsEnsuringJoin extends BaseSpecification
|
|||||||
{
|
{
|
||||||
return $this->apiKey === null || $this->apiKey->isAdmin() ? Spec::andX() : Spec::andX(
|
return $this->apiKey === null || $this->apiKey->isAdmin() ? Spec::andX() : Spec::andX(
|
||||||
Spec::join($this->fieldToJoin, 's'),
|
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…
Reference in New Issue
Block a user