2017-08-06 09:43:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API\Interaction;
|
|
|
|
|
2022-07-29 06:47:10 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
2017-08-06 09:43:59 +00:00
|
|
|
use App\Http\Requests\API\BatchInteractionRequest;
|
2022-07-29 06:47:10 +00:00
|
|
|
use App\Models\User;
|
2024-01-06 22:28:31 +00:00
|
|
|
use App\Repositories\SongRepository;
|
2022-07-29 06:47:10 +00:00
|
|
|
use App\Services\InteractionService;
|
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
2022-11-27 15:29:29 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2017-08-06 09:43:59 +00:00
|
|
|
|
|
|
|
class BatchLikeController extends Controller
|
|
|
|
{
|
2022-07-29 06:47:10 +00:00
|
|
|
/** @param User $user */
|
2024-01-06 22:28:31 +00:00
|
|
|
public function __construct(
|
|
|
|
private SongRepository $songRepository,
|
|
|
|
private InteractionService $interactionService,
|
|
|
|
private ?Authenticatable $user
|
|
|
|
) {
|
2022-07-29 06:47:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 09:50:52 +00:00
|
|
|
public function store(BatchInteractionRequest $request)
|
2017-08-06 09:43:59 +00:00
|
|
|
{
|
2024-01-06 22:28:31 +00:00
|
|
|
$this->songRepository->getMany(ids: $request->songs, scopedUser: $this->user)
|
|
|
|
->each(fn ($song) => $this->authorize('interact', $song));
|
|
|
|
|
|
|
|
$interactions = $this->interactionService->batchLike(Arr::wrap($request->songs), $this->user);
|
2018-08-18 12:27:26 +00:00
|
|
|
|
|
|
|
return response()->json($interactions);
|
2017-08-06 09:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(BatchInteractionRequest $request)
|
|
|
|
{
|
2024-01-06 22:28:31 +00:00
|
|
|
$this->songRepository->getMany(ids: $request->songs, scopedUser: $this->user)
|
|
|
|
->each(fn ($song) => $this->authorize('interact', $song));
|
|
|
|
|
2022-11-27 15:29:29 +00:00
|
|
|
$this->interactionService->batchUnlike(Arr::wrap($request->songs), $this->user);
|
2018-08-18 12:27:26 +00:00
|
|
|
|
2021-12-06 17:07:43 +00:00
|
|
|
return response()->noContent();
|
2017-08-06 09:43:59 +00:00
|
|
|
}
|
|
|
|
}
|