From 737339b6765e7e6d111ed25f805b55af2c5e2253 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Fri, 29 Jun 2018 03:27:35 +0300 Subject: [PATCH] #1 Torrent list ordering support added to API V1 '/torrents' method. --- src/Api/V1/Controller/TorrentController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Api/V1/Controller/TorrentController.php b/src/Api/V1/Controller/TorrentController.php index d278bc9..14414c0 100644 --- a/src/Api/V1/Controller/TorrentController.php +++ b/src/Api/V1/Controller/TorrentController.php @@ -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)