From 3e081df01cd8f395a19286d7cfcd2fb5239ca763 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Sun, 27 Apr 2025 16:30:08 -0500 Subject: [PATCH] fix: adds download record at time of download --- src/Controller/DownloadController.php | 11 ++++ .../Action/Command/DownloadMediaCommand.php | 1 + .../Action/Handler/DownloadMediaHandler.php | 21 +++++--- .../Action/Input/DownloadMediaInput.php | 3 ++ templates/broadcast/Download.stream.html.twig | 52 +++++++++++-------- .../components/ActiveDownloadList.html.twig | 8 +-- templates/index/index.html.twig | 2 +- 7 files changed, 62 insertions(+), 36 deletions(-) diff --git a/src/Controller/DownloadController.php b/src/Controller/DownloadController.php index d955046..18579e4 100644 --- a/src/Controller/DownloadController.php +++ b/src/Controller/DownloadController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Download\Action\Input\DownloadMediaInput; +use App\Download\Framework\Repository\DownloadRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Messenger\MessageBusInterface; @@ -11,6 +12,7 @@ use Symfony\Component\Routing\Attribute\Route; class DownloadController extends AbstractController { public function __construct( + private DownloadRepository $downloadRepository, private MessageBusInterface $bus, ) {} @@ -18,6 +20,15 @@ class DownloadController extends AbstractController public function download( DownloadMediaInput $input, ): Response { + $download = $this->downloadRepository->insert( + $input->url, + $input->title, + $input->filename, + $input->imdbId, + $input->mediaType, + "", + ); + $input->downloadId = $download->getId(); try { $this->bus->dispatch($input->toCommand()); } catch (\Throwable $exception) { diff --git a/src/Download/Action/Command/DownloadMediaCommand.php b/src/Download/Action/Command/DownloadMediaCommand.php index 10730b2..98b27ca 100644 --- a/src/Download/Action/Command/DownloadMediaCommand.php +++ b/src/Download/Action/Command/DownloadMediaCommand.php @@ -15,5 +15,6 @@ class DownloadMediaCommand implements CommandInterface public string $filename, public string $mediaType, public string $imdbId, + public ?int $downloadId = null, ) {} } \ No newline at end of file diff --git a/src/Download/Action/Handler/DownloadMediaHandler.php b/src/Download/Action/Handler/DownloadMediaHandler.php index cfaada3..9d1ceeb 100644 --- a/src/Download/Action/Handler/DownloadMediaHandler.php +++ b/src/Download/Action/Handler/DownloadMediaHandler.php @@ -21,14 +21,19 @@ readonly class DownloadMediaHandler implements HandlerInterface public function handle(CommandInterface $command): ResultInterface { - $download = $this->downloadRepository->insert( - $command->url, - $command->title, - $command->filename, - $command->imdbId, - $command->mediaType, - "" - ); + if (null === $command->downloadId) { + $download = $this->downloadRepository->insert( + $command->url, + $command->title, + $command->filename, + $command->imdbId, + $command->mediaType, + "" + ); + } else { + $download = $this->downloadRepository->find($command->downloadId); + } + try { $this->downloadRepository->updateStatus($download->getId(), 'In Progress'); diff --git a/src/Download/Action/Input/DownloadMediaInput.php b/src/Download/Action/Input/DownloadMediaInput.php index 1565776..c7acce5 100644 --- a/src/Download/Action/Input/DownloadMediaInput.php +++ b/src/Download/Action/Input/DownloadMediaInput.php @@ -25,6 +25,8 @@ class DownloadMediaInput implements InputInterface #[SourceRequest('imdbId')] public string $imdbId, + + public ?int $downloadId = null, ) {} public function toCommand(): CommandInterface @@ -35,6 +37,7 @@ class DownloadMediaInput implements InputInterface $this->filename, $this->mediaType, $this->imdbId, + $this->downloadId, ); } } \ No newline at end of file diff --git a/templates/broadcast/Download.stream.html.twig b/templates/broadcast/Download.stream.html.twig index 4ee1c83..0bbd270 100644 --- a/templates/broadcast/Download.stream.html.twig +++ b/templates/broadcast/Download.stream.html.twig @@ -11,7 +11,13 @@ {{ entity.progress }} - + + + + + + {% endblock %} @@ -20,16 +26,14 @@ {% if entity.status != "Complete" %} {% else %} @@ -42,18 +46,20 @@ -{# #} -{# #} -{# #} + + + {% endif %} {% endblock %} diff --git a/templates/components/ActiveDownloadList.html.twig b/templates/components/ActiveDownloadList.html.twig index ec422e9..908de9e 100644 --- a/templates/components/ActiveDownloadList.html.twig +++ b/templates/components/ActiveDownloadList.html.twig @@ -1,5 +1,5 @@ - +
{% endfor %} diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig index c4b1ade..bf0c2af 100644 --- a/templates/index/index.html.twig +++ b/templates/index/index.html.twig @@ -11,7 +11,7 @@ -
- - {{ download.progress }} - + + {{ download.progress }} +
+