From 665a3dbcbf5115e9111e886d1add05b42e36de6f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 4 Jan 2022 12:22:36 +0100 Subject: [PATCH] Documented tagsMode param for short URLs list --- docs/swagger/paths/v1_short-urls.json | 12 +++++++++- .../src/Repository/ShortUrlRepository.php | 7 +++--- .../ShortUrlRepositoryInterface.php | 5 ++-- .../Repository/ShortUrlRepositoryTest.php | 23 +++++++------------ 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/docs/swagger/paths/v1_short-urls.json b/docs/swagger/paths/v1_short-urls.json index 04afdd3a..6e8bb015 100644 --- a/docs/swagger/paths/v1_short-urls.json +++ b/docs/swagger/paths/v1_short-urls.json @@ -49,10 +49,20 @@ } } }, + { + "name": "tagsMode", + "in": "query", + "description": "Tells how the filtering by tags should work, returning short URLs containing \"any\" of the tags, or \"all\" the tags. It's ignored if no tags are provided, and defaults to \"any\" if not provided.", + "required": false, + "schema": { + "type": "string", + "enum": ["any", "all"] + } + }, { "name": "orderBy", "in": "query", - "description": "The field from which you want to order the result. (Since v1.3.0)", + "description": "The field from which you want to order the result.", "required": false, "schema": { "type": "string", diff --git a/module/Core/src/Repository/ShortUrlRepository.php b/module/Core/src/Repository/ShortUrlRepository.php index 88a79e34..aaa0bcca 100644 --- a/module/Core/src/Repository/ShortUrlRepository.php +++ b/module/Core/src/Repository/ShortUrlRepository.php @@ -16,7 +16,6 @@ use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\ShortUrlMeta; use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering; -use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl; use function array_column; @@ -34,7 +33,7 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU ?int $offset = null, ?string $searchTerm = null, array $tags = [], - string $tagsMode = ShortUrlsParams::TAGS_MODE_ANY, + ?string $tagsMode = null, ?ShortUrlsOrdering $orderBy = null, ?DateRange $dateRange = null, ?Specification $spec = null, @@ -80,7 +79,7 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU public function countList( ?string $searchTerm = null, array $tags = [], - string $tagsMode = ShortUrlsParams::TAGS_MODE_ANY, + ?string $tagsMode = null, ?DateRange $dateRange = null, ?Specification $spec = null, ): int { @@ -93,7 +92,7 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU private function createListQueryBuilder( ?string $searchTerm, array $tags, - string $tagsMode, + ?string $tagsMode, ?DateRange $dateRange, ?Specification $spec, ): QueryBuilder { diff --git a/module/Core/src/Repository/ShortUrlRepositoryInterface.php b/module/Core/src/Repository/ShortUrlRepositoryInterface.php index 02f5b5be..c3bd8d7f 100644 --- a/module/Core/src/Repository/ShortUrlRepositoryInterface.php +++ b/module/Core/src/Repository/ShortUrlRepositoryInterface.php @@ -12,7 +12,6 @@ use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\ShortUrlMeta; use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering; -use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl; interface ShortUrlRepositoryInterface extends ObjectRepository, EntitySpecificationRepositoryInterface @@ -22,7 +21,7 @@ interface ShortUrlRepositoryInterface extends ObjectRepository, EntitySpecificat ?int $offset = null, ?string $searchTerm = null, array $tags = [], - string $tagsMode = ShortUrlsParams::TAGS_MODE_ANY, + ?string $tagsMode = null, ?ShortUrlsOrdering $orderBy = null, ?DateRange $dateRange = null, ?Specification $spec = null, @@ -31,7 +30,7 @@ interface ShortUrlRepositoryInterface extends ObjectRepository, EntitySpecificat public function countList( ?string $searchTerm = null, array $tags = [], - string $tagsMode = ShortUrlsParams::TAGS_MODE_ANY, + ?string $tagsMode = null, ?DateRange $dateRange = null, ?Specification $spec = null, ): int; diff --git a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php index b7c83a61..69ef7143 100644 --- a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php @@ -14,7 +14,6 @@ use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\ShortUrlMeta; use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering; -use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Repository\ShortUrlRepository; use Shlinkio\Shlink\Core\ShortUrl\Resolver\PersistenceShortUrlRelationResolver; @@ -128,29 +127,28 @@ class ShortUrlRepositoryTest extends DatabaseTestCase self::assertCount(1, $this->repo->findList(2, 2)); - $tagsModeAll = ShortUrlsParams::TAGS_MODE_ANY; - $result = $this->repo->findList(null, null, null, [], $tagsModeAll, ShortUrlsOrdering::fromRawData([ + $result = $this->repo->findList(null, null, null, [], null, ShortUrlsOrdering::fromRawData([ 'orderBy' => 'visits-DESC', ])); self::assertCount(3, $result); self::assertSame($bar, $result[0]); - $result = $this->repo->findList(null, null, null, [], $tagsModeAll, null, DateRange::withEndDate( + $result = $this->repo->findList(null, null, null, [], null, null, DateRange::withEndDate( Chronos::now()->subDays(2), )); self::assertCount(1, $result); - self::assertEquals(1, $this->repo->countList(null, [], $tagsModeAll, DateRange::withEndDate( + self::assertEquals(1, $this->repo->countList(null, [], null, DateRange::withEndDate( Chronos::now()->subDays(2), ))); self::assertSame($foo2, $result[0]); self::assertCount( 2, - $this->repo->findList(null, null, null, [], $tagsModeAll, null, DateRange::withStartDate( + $this->repo->findList(null, null, null, [], null, null, DateRange::withStartDate( Chronos::now()->subDays(2), )), ); - self::assertEquals(2, $this->repo->countList(null, [], $tagsModeAll, DateRange::withStartDate( + self::assertEquals(2, $this->repo->countList(null, [], null, DateRange::withStartDate( Chronos::now()->subDays(2), ))); } @@ -165,14 +163,9 @@ class ShortUrlRepositoryTest extends DatabaseTestCase $this->getEntityManager()->flush(); - $result = $this->repo->findList( - null, - null, - null, - [], - ShortUrlsParams::TAGS_MODE_ANY, - ShortUrlsOrdering::fromRawData(['orderBy' => 'longUrl-ASC']), - ); + $result = $this->repo->findList(null, null, null, [], null, ShortUrlsOrdering::fromRawData([ + 'orderBy' => 'longUrl-ASC', + ])); self::assertCount(count($urls), $result); self::assertEquals('a', $result[0]->getLongUrl());