mirror of
https://github.com/koel/koel
synced 2024-12-04 09:49:23 +00:00
40 lines
1 KiB
PHP
40 lines
1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\API;
|
||
|
|
||
|
use App\Http\Requests\API\PlaylistSongUpdateRequest;
|
||
|
use App\Models\Playlist;
|
||
|
use App\Services\SmartPlaylistService;
|
||
|
|
||
|
class PlaylistSongController extends Controller
|
||
|
{
|
||
|
private SmartPlaylistService $smartPlaylistService;
|
||
|
|
||
|
public function __construct(SmartPlaylistService $smartPlaylistService)
|
||
|
{
|
||
|
$this->smartPlaylistService = $smartPlaylistService;
|
||
|
}
|
||
|
|
||
|
public function index(Playlist $playlist)
|
||
|
{
|
||
|
$this->authorize('owner', $playlist);
|
||
|
|
||
|
return response()->json(
|
||
|
$playlist->is_smart
|
||
|
? $this->smartPlaylistService->getSongs($playlist)->pluck('id')
|
||
|
: $playlist->songs->pluck('id')
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public function update(PlaylistSongUpdateRequest $request, Playlist $playlist)
|
||
|
{
|
||
|
$this->authorize('owner', $playlist);
|
||
|
|
||
|
abort_if($playlist->is_smart, 403, 'A smart playlist\'s content cannot be updated manually.');
|
||
|
|
||
|
$playlist->songs()->sync((array) $request->songs);
|
||
|
|
||
|
return response()->json();
|
||
|
}
|
||
|
}
|