2020-12-24 22:35:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API\Search;
|
|
|
|
|
|
|
|
use App\Http\Controllers\API\Controller;
|
|
|
|
use App\Services\SearchService;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
|
|
|
|
class SongSearchController extends Controller
|
|
|
|
{
|
|
|
|
private $searchService;
|
|
|
|
|
|
|
|
public function __construct(SearchService $searchService)
|
|
|
|
{
|
|
|
|
$this->searchService = $searchService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
if (!$request->get('q')) {
|
|
|
|
throw new InvalidArgumentException('A search query is required.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2020-12-25 11:52:28 +00:00
|
|
|
'songs' => $this->searchService->searchSongs($request->get('q')),
|
2020-12-24 22:35:39 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|