2024-01-02 13:10:06 +00:00
|
|
|
<?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;
|
2024-01-02 13:10:06 +00:00
|
|
|
use App\Models\User;
|
2024-01-06 22:28:31 +00:00
|
|
|
use App\Repositories\SongRepository;
|
2024-01-02 13:10:06 +00:00
|
|
|
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,
|
2024-01-02 13:10:06 +00:00
|
|
|
InteractionService $interactionService,
|
2024-01-06 22:28:31 +00:00
|
|
|
?Authenticatable $user
|
2024-01-02 13:10:06 +00:00
|
|
|
) {
|
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));
|
2024-01-02 13:10:06 +00:00
|
|
|
}
|
|
|
|
}
|