From d0546a2ea2817eab0f77ecc2edfbdfece1d9b710 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 18 Jan 2022 20:14:24 +0100 Subject: [PATCH] Split spec to join ApiKey spec with short URLs, into inlined and regular versions --- module/Core/src/Repository/TagRepository.php | 5 ++-- .../Spec/WithApiKeySpecsEnsuringJoin.php | 9 +++---- .../WithInlinedApiKeySpecsEnsuringJoin.php | 26 +++++++++++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 module/Rest/src/ApiKey/Spec/WithInlinedApiKeySpecsEnsuringJoin.php diff --git a/module/Core/src/Repository/TagRepository.php b/module/Core/src/Repository/TagRepository.php index f19e8917..8e6e2080 100644 --- a/module/Core/src/Repository/TagRepository.php +++ b/module/Core/src/Repository/TagRepository.php @@ -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(); diff --git a/module/Rest/src/ApiKey/Spec/WithApiKeySpecsEnsuringJoin.php b/module/Rest/src/ApiKey/Spec/WithApiKeySpecsEnsuringJoin.php index 56f64a6d..1f8c2fd3 100644 --- a/module/Rest/src/ApiKey/Spec/WithApiKeySpecsEnsuringJoin.php +++ b/module/Rest/src/ApiKey/Spec/WithApiKeySpecsEnsuringJoin.php @@ -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), ); } } diff --git a/module/Rest/src/ApiKey/Spec/WithInlinedApiKeySpecsEnsuringJoin.php b/module/Rest/src/ApiKey/Spec/WithInlinedApiKeySpecsEnsuringJoin.php new file mode 100644 index 00000000..8e535570 --- /dev/null +++ b/module/Rest/src/ApiKey/Spec/WithInlinedApiKeySpecsEnsuringJoin.php @@ -0,0 +1,26 @@ +apiKey === null || $this->apiKey->isAdmin() ? Spec::andX() : Spec::andX( + Spec::join($this->fieldToJoin, 's'), + $this->apiKey->inlinedSpec(), + ); + } +}