mirror of
https://github.com/koel/koel
synced 2024-12-13 06:02:27 +00:00
42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API\Interaction;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\API\BatchInteractionRequest;
|
|
use App\Models\User;
|
|
use App\Repositories\SongRepository;
|
|
use App\Services\InteractionService;
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class BatchLikeController extends Controller
|
|
{
|
|
/** @param User $user */
|
|
public function __construct(
|
|
private SongRepository $songRepository,
|
|
private InteractionService $interactionService,
|
|
private ?Authenticatable $user
|
|
) {
|
|
}
|
|
|
|
public function store(BatchInteractionRequest $request)
|
|
{
|
|
$this->songRepository->getMany(ids: $request->songs, scopedUser: $this->user)
|
|
->each(fn ($song) => $this->authorize('access', $song));
|
|
|
|
$interactions = $this->interactionService->batchLike(Arr::wrap($request->songs), $this->user);
|
|
|
|
return response()->json($interactions);
|
|
}
|
|
|
|
public function destroy(BatchInteractionRequest $request)
|
|
{
|
|
$this->songRepository->getMany(ids: $request->songs, scopedUser: $this->user)
|
|
->each(fn ($song) => $this->authorize('access', $song));
|
|
|
|
$this->interactionService->batchUnlike(Arr::wrap($request->songs), $this->user);
|
|
|
|
return response()->noContent();
|
|
}
|
|
}
|