koel/app/Http/Controllers/V6/API/SongController.php

36 lines
918 B
PHP
Raw Normal View History

2022-06-10 10:47:46 +00:00
<?php
namespace App\Http\Controllers\V6\API;
2022-07-29 06:47:10 +00:00
use App\Http\Controllers\Controller;
2022-06-10 10:47:46 +00:00
use App\Http\Controllers\V6\Requests\SongListRequest;
use App\Http\Resources\SongResource;
2022-07-05 21:43:35 +00:00
use App\Models\Song;
2022-06-10 10:47:46 +00:00
use App\Models\User;
use App\Repositories\SongRepository;
use Illuminate\Contracts\Auth\Authenticatable;
class SongController extends Controller
{
/** @param User $user */
public function __construct(private SongRepository $songRepository, private ?Authenticatable $user)
{
}
2022-07-05 21:43:35 +00:00
public function show(Song $song)
{
return SongResource::make($this->songRepository->getOne($song->id));
}
2022-06-10 10:47:46 +00:00
public function index(SongListRequest $request)
{
return SongResource::collection(
$this->songRepository->getForListing(
$request->sort ?: 'songs.title',
$request->order ?: 'asc',
$this->user
)
);
}
}