mirror of
https://github.com/koel/koel
synced 2025-03-04 15:17:13 +00:00
35 lines
835 B
PHP
35 lines
835 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\API\Search;
|
||
|
|
||
|
use App\Http\Controllers\API\Controller;
|
||
|
use App\Models\Song;
|
||
|
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 [
|
||
|
'songs' => $this->searchService->searchSongs($request->get('q'))
|
||
|
->get()
|
||
|
->map(static function (Song $song): string {
|
||
|
return $song->id;
|
||
|
}),
|
||
|
];
|
||
|
}
|
||
|
}
|