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