mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-26 23:18:37 +03:00
Updated paginator types
This commit is contained in:
parent
3a4550fe24
commit
f361403888
9 changed files with 23 additions and 13 deletions
|
@ -47,7 +47,7 @@
|
|||
"pugx/shortid-php": "^1.0",
|
||||
"ramsey/uuid": "^4.2",
|
||||
"rlanvin/php-ip": "dev-master#6b3a785 as 3.0",
|
||||
"shlinkio/shlink-common": "dev-main#a6cbcb6 as 4.2",
|
||||
"shlinkio/shlink-common": "dev-main#c2e3442 as 4.2",
|
||||
"shlinkio/shlink-config": "^1.4",
|
||||
"shlinkio/shlink-event-dispatcher": "dev-main#3925299 as 2.3",
|
||||
"shlinkio/shlink-importer": "dev-main#d099072 as 2.5",
|
||||
|
|
|
@ -131,7 +131,7 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
|
|||
];
|
||||
|
||||
if ($all) {
|
||||
$data[ShortUrlsParamsInputFilter::ITEMS_PER_PAGE] = -1;
|
||||
$data[ShortUrlsParamsInputFilter::ITEMS_PER_PAGE] = Paginator::ALL_ITEMS;
|
||||
}
|
||||
|
||||
do {
|
||||
|
|
|
@ -271,7 +271,7 @@ class ListShortUrlsCommandTest extends TestCase
|
|||
'startDate' => null,
|
||||
'endDate' => null,
|
||||
'orderBy' => null,
|
||||
'itemsPerPage' => -1,
|
||||
'itemsPerPage' => Paginator::ALL_ITEMS,
|
||||
]))->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->execute(['--all' => true]);
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shlinkio\Shlink\Core\Model;
|
||||
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
|
||||
use function Shlinkio\Shlink\Core\parseDateRangeFromQuery;
|
||||
|
@ -11,7 +12,6 @@ use function Shlinkio\Shlink\Core\parseDateRangeFromQuery;
|
|||
final class VisitsParams
|
||||
{
|
||||
private const FIRST_PAGE = 1;
|
||||
private const ALL_ITEMS = -1;
|
||||
|
||||
private DateRange $dateRange;
|
||||
private int $page;
|
||||
|
@ -36,10 +36,10 @@ final class VisitsParams
|
|||
private function determineItemsPerPage(?int $itemsPerPage): int
|
||||
{
|
||||
if ($itemsPerPage !== null && $itemsPerPage < 0) {
|
||||
return self::ALL_ITEMS;
|
||||
return Paginator::ALL_ITEMS;
|
||||
}
|
||||
|
||||
return $itemsPerPage ?? self::ALL_ITEMS;
|
||||
return $itemsPerPage ?? Paginator::ALL_ITEMS;
|
||||
}
|
||||
|
||||
public static function fromRawData(array $query): self
|
||||
|
|
|
@ -226,8 +226,6 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo
|
|||
'id' => 'visit_location_id',
|
||||
]);
|
||||
|
||||
$query = $this->getEntityManager()->createNativeQuery($nativeQb->getSQL(), $rsm);
|
||||
|
||||
return $query->getResult();
|
||||
return $this->getEntityManager()->createNativeQuery($nativeQb->getSQL(), $rsm)->getResult();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Shlinkio\Shlink\Core\Validation;
|
||||
|
||||
use Laminas\InputFilter\InputFilter;
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\Common\Validation;
|
||||
|
||||
class ShortUrlsParamsInputFilter extends InputFilter
|
||||
|
@ -32,7 +33,7 @@ class ShortUrlsParamsInputFilter extends InputFilter
|
|||
$this->add($this->createInput(self::SEARCH_TERM, false));
|
||||
|
||||
$this->add($this->createNumericInput(self::PAGE, false));
|
||||
$this->add($this->createNumericInput(self::ITEMS_PER_PAGE, false, -1));
|
||||
$this->add($this->createNumericInput(self::ITEMS_PER_PAGE, false, Paginator::ALL_ITEMS));
|
||||
|
||||
$this->add($this->createTagsInput(self::TAGS, false));
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
class OrphanVisitsTest extends ApiTestCase
|
||||
|
@ -51,7 +52,7 @@ class OrphanVisitsTest extends ApiTestCase
|
|||
$payload = $this->getJsonResponsePayload($resp);
|
||||
$visits = $payload['visits']['data'] ?? [];
|
||||
|
||||
self::assertEquals($totalItems, $payload['visits']['pagination']['totalItems'] ?? -1);
|
||||
self::assertEquals($totalItems, $payload['visits']['pagination']['totalItems'] ?? Paginator::ALL_ITEMS);
|
||||
self::assertCount($expectedAmount, $visits);
|
||||
self::assertEquals($expectedVisits, $visits);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|||
|
||||
use GuzzleHttp\Psr7\Query;
|
||||
use Laminas\Diactoros\Uri;
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
use ShlinkioApiTest\Shlink\Rest\Utils\NotFoundUrlHelpersTrait;
|
||||
|
||||
|
@ -58,7 +59,10 @@ class ShortUrlVisitsTest extends ApiTestCase
|
|||
$resp = $this->callApiWithKey(self::METHOD_GET, (string) $url);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
self::assertEquals($expectedAmountOfVisits, $payload['visits']['pagination']['totalItems'] ?? -1);
|
||||
self::assertEquals(
|
||||
$expectedAmountOfVisits,
|
||||
$payload['visits']['pagination']['totalItems'] ?? Paginator::ALL_ITEMS,
|
||||
);
|
||||
self::assertCount($expectedAmountOfVisits, $payload['visits']['data'] ?? []);
|
||||
}
|
||||
|
||||
|
@ -84,7 +88,10 @@ class ShortUrlVisitsTest extends ApiTestCase
|
|||
$resp = $this->callApiWithKey(self::METHOD_GET, (string) $url);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
self::assertEquals($expectedAmountOfVisits, $payload['visits']['pagination']['totalItems'] ?? -1);
|
||||
self::assertEquals(
|
||||
$expectedAmountOfVisits,
|
||||
$payload['visits']['pagination']['totalItems'] ?? Paginator::ALL_ITEMS,
|
||||
);
|
||||
self::assertCount($expectedAmountOfVisits, $payload['visits']['data'] ?? []);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,3 +9,6 @@ parameters:
|
|||
doctrine:
|
||||
repositoryClass: Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository
|
||||
objectManagerLoader: 'config/entity-manager.php'
|
||||
ignoreErrors:
|
||||
- '#should return int<0, max> but returns int#'
|
||||
- '#expects -1|int<1, max>, int given#'
|
||||
|
|
Loading…
Reference in a new issue