2022-10-21 20:06:43 +00:00
|
|
|
<?php
|
|
|
|
|
2023-06-05 21:46:41 +00:00
|
|
|
namespace App\Http\Controllers\API;
|
2022-10-21 20:06:43 +00:00
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2023-06-05 21:46:41 +00:00
|
|
|
use App\Http\Requests\API\GenreFetchSongRequest;
|
2022-10-21 20:06:43 +00:00
|
|
|
use App\Http\Resources\SongResource;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Repositories\SongRepository;
|
|
|
|
use App\Values\Genre;
|
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
|
|
|
|
|
|
class GenreSongController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
|
|
|
public function __invoke(
|
|
|
|
string $genre,
|
|
|
|
SongRepository $repository,
|
|
|
|
Authenticatable $user,
|
|
|
|
GenreFetchSongRequest $request
|
|
|
|
) {
|
|
|
|
return SongResource::collection(
|
|
|
|
$repository->getByGenre(
|
2022-11-27 15:29:29 +00:00
|
|
|
$genre === Genre::NO_GENRE ? '' : $genre,
|
2024-05-19 05:49:42 +00:00
|
|
|
$request->sort ? explode(',', $request->sort) : ['songs.title'],
|
2022-10-21 20:06:43 +00:00
|
|
|
$request->order ?: 'asc',
|
|
|
|
$user
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|