#1 Torrent list ordering support added to API V1 '/torrents' method.

This commit is contained in:
Alexey Skobkin 2018-06-29 03:27:35 +03:00
parent b6bd4f211a
commit 737339b676

View file

@ -4,7 +4,7 @@ namespace App\Api\V1\Controller;
use App\Api\V1\DTO\ListPage;
use App\Magnetico\Entity\Torrent;
use App\Magnetico\Repository\TorrentRepository;
use App\Search\TorrentSearcher;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\{JsonResponse, Request};
@ -13,12 +13,14 @@ class TorrentController extends AbstractApiController
{
private const PER_PAGE = 20;
public function search(Request $request, TorrentRepository $repo): JsonResponse
public function search(Request $request, TorrentSearcher $searcher): JsonResponse
{
$query = $request->query->get('query', '');
$page = (int) $request->query->get('page', '1');
$orderBy = $request->query->get('order-by');
$order = $request->query->get('order', 'asc');
$pagerAdapter = new DoctrineORMAdapter($repo->createFindLikeQueryBuilder($query));
$pagerAdapter = new DoctrineORMAdapter($searcher->createSearchQueryBuilder($query, $orderBy, $order));
$pager = new Pagerfanta($pagerAdapter);
$pager
->setCurrentPage($page)