koel/app/Http/Controllers/API/Download/FavoritesController.php
2018-08-22 22:25:01 +02:00

34 lines
900 B
PHP

<?php
namespace App\Http\Controllers\API\Download;
use App\Http\Requests\API\Download\Request;
use App\Models\Song;
use App\Services\DownloadService;
use App\Services\InteractionService;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class FavoritesController extends Controller
{
private $interactionService;
public function __construct(DownloadService $downloadService, InteractionService $interactionService)
{
parent::__construct($downloadService);
$this->interactionService = $interactionService;
}
/**
* Download all songs in a playlist.
*
* @param Request $request
*
* @return BinaryFileResponse
*/
public function show(Request $request)
{
$songs = $this->interactionService->getUserFavorites($request->user());
return response()->download($this->downloadService->from($songs));
}
}