Created DTOs with implicit validation to wrap short URLs lists params

This commit is contained in:
Alejandro Celaya
2020-01-28 10:49:55 +01:00
parent 240d2588f9
commit 452bfea088
15 changed files with 335 additions and 166 deletions

View File

@@ -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;
}

View File

@@ -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