2022-08-10 14:56:01 +00:00
|
|
|
<?php
|
|
|
|
|
2023-06-05 21:46:41 +00:00
|
|
|
namespace App\Http\Controllers\API;
|
2022-08-10 14:56:01 +00:00
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2023-06-05 21:46:41 +00:00
|
|
|
use App\Http\Requests\API\PlaylistFolderStoreRequest;
|
|
|
|
use App\Http\Requests\API\PlaylistFolderUpdateRequest;
|
2022-08-10 14:56:01 +00:00
|
|
|
use App\Http\Resources\PlaylistFolderResource;
|
|
|
|
use App\Models\PlaylistFolder;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Services\PlaylistFolderService;
|
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
|
|
|
|
|
|
class PlaylistFolderController extends Controller
|
|
|
|
{
|
|
|
|
/** @param User $user */
|
2024-04-18 14:36:28 +00:00
|
|
|
public function __construct(
|
|
|
|
private readonly PlaylistFolderService $service,
|
|
|
|
private readonly ?Authenticatable $user
|
|
|
|
) {
|
2022-08-10 14:56:01 +00:00
|
|
|
}
|
|
|
|
|
2023-08-16 12:56:31 +00:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return PlaylistFolderResource::collection($this->user->playlist_folders);
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:56:01 +00:00
|
|
|
public function store(PlaylistFolderStoreRequest $request)
|
|
|
|
{
|
|
|
|
return PlaylistFolderResource::make($this->service->createFolder($this->user, $request->name));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(PlaylistFolder $playlistFolder, PlaylistFolderUpdateRequest $request)
|
|
|
|
{
|
|
|
|
$this->authorize('own', $playlistFolder);
|
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
return PlaylistFolderResource::make($this->service->renameFolder($playlistFolder, $request->name));
|
2022-08-10 14:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(PlaylistFolder $playlistFolder)
|
|
|
|
{
|
|
|
|
$this->authorize('own', $playlistFolder);
|
|
|
|
|
|
|
|
$playlistFolder->delete();
|
|
|
|
|
|
|
|
return response()->noContent();
|
|
|
|
}
|
|
|
|
}
|