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

48 lines
1.3 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Controllers\API;
2016-03-05 09:01:12 +00:00
use App\Http\Requests\API\SongUpdateRequest;
2017-04-24 06:38:41 +00:00
use App\Models\Song;
2018-08-29 06:30:39 +00:00
use App\Repositories\AlbumRepository;
use App\Repositories\ArtistRepository;
2017-06-04 01:30:45 +00:00
use Illuminate\Http\JsonResponse;
2015-12-13 04:42:28 +00:00
/**
* @group 3. Song interactions
*/
2015-12-13 04:42:28 +00:00
class SongController extends Controller
{
2018-08-29 06:30:39 +00:00
private $artistRepository;
private $albumRepository;
2018-08-18 13:19:40 +00:00
2018-08-29 06:30:39 +00:00
public function __construct(
ArtistRepository $artistRepository,
AlbumRepository $albumRepository
2018-08-29 07:07:44 +00:00
) {
2018-08-29 06:30:39 +00:00
$this->artistRepository = $artistRepository;
$this->albumRepository = $albumRepository;
2018-08-18 13:19:40 +00:00
}
2016-03-05 09:01:12 +00:00
/**
* Update song information
*
* @bodyParam songs array required An array of song IDs to be updated.
* @bodyParam data object required The new data, with these supported fields: `title`, `artistName`, `albumName`, and `lyrics`.
*
* @group 5. Media information
2016-03-05 09:01:12 +00:00
*
2017-06-04 01:30:45 +00:00
* @return JsonResponse
2016-03-05 09:01:12 +00:00
*/
public function update(SongUpdateRequest $request)
{
2018-08-29 06:30:39 +00:00
$updatedSongs = Song::updateInfo($request->songs, $request->data);
return response()->json([
'artists' => $this->artistRepository->getByIds($updatedSongs->pluck('artist_id')->all()),
'albums' => $this->albumRepository->getByIds($updatedSongs->pluck('album_id')->all()),
'songs' => $updatedSongs,
]);
2016-03-05 09:01:12 +00:00
}
2015-12-13 04:42:28 +00:00
}