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

28 lines
770 B
PHP
Raw Normal View History

<?php
2024-01-10 21:37:24 +00:00
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use App\Http\Requests\API\ToggleLikeSongRequest;
2024-01-06 22:28:31 +00:00
use App\Http\Resources\InteractionResource;
2024-01-10 21:37:24 +00:00
use App\Models\Song;
use App\Models\User;
use App\Services\InteractionService;
use Illuminate\Contracts\Auth\Authenticatable;
class ToggleLikeSongController extends Controller
{
/** @param User $user */
public function __invoke(
ToggleLikeSongRequest $request,
InteractionService $interactionService,
2024-01-06 22:28:31 +00:00
?Authenticatable $user
) {
2024-01-10 21:37:24 +00:00
/** @var Song $song */
$song = Song::query()->findOrFail($request->song);
2024-01-09 11:53:35 +00:00
$this->authorize('access', $song);
2024-01-06 22:28:31 +00:00
2024-01-10 21:37:24 +00:00
return InteractionResource::make($interactionService->toggleLike($song, $user));
}
}