2024-01-02 13:10:06 +00:00
|
|
|
<?php
|
|
|
|
|
2024-01-10 21:37:24 +00:00
|
|
|
namespace App\Http\Controllers\API;
|
2024-01-02 13:10:06 +00:00
|
|
|
|
|
|
|
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;
|
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-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));
|
2024-01-02 13:10:06 +00:00
|
|
|
}
|
|
|
|
}
|