30 lines
904 B
PHP
30 lines
904 B
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Download\Action\Input\DownloadMediaInput;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
class DownloadController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private MessageBusInterface $bus,
|
|
) {}
|
|
|
|
#[Route('/download', name: 'app_download', methods: ['POST'])]
|
|
public function download(
|
|
DownloadMediaInput $input,
|
|
): Response {
|
|
try {
|
|
$this->bus->dispatch($input->toCommand());
|
|
} catch (\Throwable $exception) {
|
|
return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
|
|
}
|
|
}
|