2015-12-13 12:42:28 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
2016-03-05 17:01:12 +08:00
|
|
|
use App\Http\Requests\API\SongUpdateRequest;
|
2017-04-24 14:38:41 +08:00
|
|
|
use App\Models\Song;
|
2018-08-29 13:30:39 +07:00
|
|
|
use App\Repositories\AlbumRepository;
|
|
|
|
use App\Repositories\ArtistRepository;
|
2015-12-13 12:42:28 +08:00
|
|
|
|
|
|
|
class SongController extends Controller
|
|
|
|
{
|
2021-06-05 12:47:56 +02:00
|
|
|
private ArtistRepository $artistRepository;
|
|
|
|
private AlbumRepository $albumRepository;
|
2018-08-18 15:19:40 +02:00
|
|
|
|
2021-06-05 12:47:56 +02:00
|
|
|
public function __construct(ArtistRepository $artistRepository, AlbumRepository $albumRepository)
|
|
|
|
{
|
2018-08-29 13:30:39 +07:00
|
|
|
$this->artistRepository = $artistRepository;
|
|
|
|
$this->albumRepository = $albumRepository;
|
2018-08-18 15:19:40 +02:00
|
|
|
}
|
|
|
|
|
2016-03-05 17:01:12 +08:00
|
|
|
public function update(SongUpdateRequest $request)
|
|
|
|
{
|
2018-08-29 13:30:39 +07: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 17:01:12 +08:00
|
|
|
}
|
2015-12-13 12:42:28 +08:00
|
|
|
}
|