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

28 lines
821 B
PHP
Raw Normal View History

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