koel/app/Http/Controllers/V6/API/QueueController.php
2022-07-29 09:04:44 +02:00

34 lines
1,004 B
PHP

<?php
namespace App\Http\Controllers\V6\API;
use App\Http\Controllers\Controller;
use App\Http\Controllers\V6\Requests\QueueFetchSongRequest;
use App\Http\Resources\SongResource;
use App\Models\User;
use App\Repositories\SongRepository;
use Illuminate\Contracts\Auth\Authenticatable;
class QueueController extends Controller
{
/** @param User $user */
public function __construct(private SongRepository $songRepository, private ?Authenticatable $user)
{
}
public function fetchSongs(QueueFetchSongRequest $request)
{
if ($request->order === 'rand') {
return SongResource::collection($this->songRepository->getRandom($request->limit, $this->user));
} else {
return SongResource::collection(
$this->songRepository->getForQueue(
$request->sort,
$request->order,
$request->limit,
$this->user,
)
);
}
}
}