mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 09:43:13 +08:00
Created DTOs with implicit validation to wrap short URLs lists params
This commit is contained in:
@@ -6,10 +6,10 @@ namespace Shlinkio\Shlink\Core\Service;
|
||||
|
||||
use Doctrine\ORM;
|
||||
use Laminas\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
|
||||
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
|
||||
use Shlinkio\Shlink\Core\Model\ShortUrlsParams;
|
||||
use Shlinkio\Shlink\Core\Paginator\Adapter\ShortUrlRepositoryAdapter;
|
||||
use Shlinkio\Shlink\Core\Repository\ShortUrlRepository;
|
||||
use Shlinkio\Shlink\Core\Service\ShortUrl\FindShortCodeTrait;
|
||||
@@ -28,23 +28,15 @@ class ShortUrlService implements ShortUrlServiceInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $tags
|
||||
* @param array|string|null $orderBy
|
||||
*
|
||||
* @return ShortUrl[]|Paginator
|
||||
*/
|
||||
public function listShortUrls(
|
||||
int $page = 1,
|
||||
?string $searchQuery = null,
|
||||
array $tags = [],
|
||||
$orderBy = null,
|
||||
?DateRange $dateRange = null
|
||||
) {
|
||||
public function listShortUrls(ShortUrlsParams $params): Paginator
|
||||
{
|
||||
/** @var ShortUrlRepository $repo */
|
||||
$repo = $this->em->getRepository(ShortUrl::class);
|
||||
$paginator = new Paginator(new ShortUrlRepositoryAdapter($repo, $searchQuery, $tags, $orderBy, $dateRange));
|
||||
$paginator = new Paginator(new ShortUrlRepositoryAdapter($repo, $params));
|
||||
$paginator->setItemCountPerPage(ShortUrlRepositoryAdapter::ITEMS_PER_PAGE)
|
||||
->setCurrentPageNumber($page);
|
||||
->setCurrentPageNumber($params->page());
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
|
||||
@@ -5,26 +5,17 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink\Core\Service;
|
||||
|
||||
use Laminas\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
|
||||
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
|
||||
use Shlinkio\Shlink\Core\Model\ShortUrlsParams;
|
||||
|
||||
interface ShortUrlServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param string[] $tags
|
||||
* @param array|string|null $orderBy
|
||||
*
|
||||
* @return ShortUrl[]|Paginator
|
||||
*/
|
||||
public function listShortUrls(
|
||||
int $page = 1,
|
||||
?string $searchQuery = null,
|
||||
array $tags = [],
|
||||
$orderBy = null,
|
||||
?DateRange $dateRange = null
|
||||
);
|
||||
public function listShortUrls(ShortUrlsParams $params): Paginator;
|
||||
|
||||
/**
|
||||
* @param string[] $tags
|
||||
|
||||
Reference in New Issue
Block a user