From cd46d8ef38ee7d5a6f247327f96c9b2a61d32058 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 17 May 2021 00:11:42 +0800 Subject: [PATCH] api snatch controller --- app/Http/Controllers/SnatchController.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/SnatchController.php b/app/Http/Controllers/SnatchController.php index 3a92f19e..d49ec3ef 100644 --- a/app/Http/Controllers/SnatchController.php +++ b/app/Http/Controllers/SnatchController.php @@ -6,10 +6,17 @@ use App\Http\Resources\PeerResource; use App\Http\Resources\SnatchResource; use App\Models\Peer; use App\Models\Snatch; +use App\Repositories\TorrentRepository; use Illuminate\Http\Request; class SnatchController extends Controller { + private $repository; + + public function __construct(TorrentRepository $repository) + { + $this->repository = $repository; + } /** * @param Request $request * @return array @@ -19,8 +26,7 @@ class SnatchController extends Controller $request->validate([ 'torrent_id' => 'required', ]); - - $snatches = Snatch::query()->where('torrentid', $torrentId)->with(['user'])->paginate(); + $snatches = $this->repository->listSnatches($request->torrent_id); $resource = SnatchResource::collection($snatches); $resource->additional(['card_titles' => Snatch::$cardTitles]);