koel/app/Http/Controllers/API/PlaylistSongController.php

46 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers\API;
2022-07-29 06:47:10 +00:00
use App\Http\Controllers\Controller;
use App\Http\Requests\API\PlaylistSongUpdateRequest;
use App\Models\Playlist;
use App\Models\User;
2022-07-29 06:47:10 +00:00
use App\Services\PlaylistService;
use App\Services\SmartPlaylistService;
use Illuminate\Contracts\Auth\Authenticatable;
class PlaylistSongController extends Controller
{
/** @param User $user */
2022-07-29 06:47:10 +00:00
public function __construct(
private SmartPlaylistService $smartPlaylistService,
private PlaylistService $playlistService,
private Authenticatable $user
2022-07-29 06:47:10 +00:00
) {
}
public function index(Playlist $playlist)
{
$this->authorize('owner', $playlist);
return response()->json(
$playlist->is_smart
? $this->smartPlaylistService->getSongs($playlist, $this->user)->pluck('id')
: $playlist->songs->pluck('id')
);
}
2022-07-29 06:47:10 +00:00
/** @deprecated */
public function update(PlaylistSongUpdateRequest $request, Playlist $playlist)
{
$this->authorize('owner', $playlist);
2022-07-29 06:47:10 +00:00
abort_if($playlist->is_smart, 403, 'A smart playlist cannot be populated manually.');
2022-07-29 06:47:10 +00:00
$this->playlistService->populatePlaylist($playlist, (array) $request->songs);
2022-07-29 06:47:10 +00:00
return response()->noContent();
}
}