fix: adds download record at time of download
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Download\Action\Input\DownloadMediaInput;
|
use App\Download\Action\Input\DownloadMediaInput;
|
||||||
|
use App\Download\Framework\Repository\DownloadRepository;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
@@ -11,6 +12,7 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||||||
class DownloadController extends AbstractController
|
class DownloadController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
private DownloadRepository $downloadRepository,
|
||||||
private MessageBusInterface $bus,
|
private MessageBusInterface $bus,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -18,6 +20,15 @@ class DownloadController extends AbstractController
|
|||||||
public function download(
|
public function download(
|
||||||
DownloadMediaInput $input,
|
DownloadMediaInput $input,
|
||||||
): Response {
|
): Response {
|
||||||
|
$download = $this->downloadRepository->insert(
|
||||||
|
$input->url,
|
||||||
|
$input->title,
|
||||||
|
$input->filename,
|
||||||
|
$input->imdbId,
|
||||||
|
$input->mediaType,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
$input->downloadId = $download->getId();
|
||||||
try {
|
try {
|
||||||
$this->bus->dispatch($input->toCommand());
|
$this->bus->dispatch($input->toCommand());
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ class DownloadMediaCommand implements CommandInterface
|
|||||||
public string $filename,
|
public string $filename,
|
||||||
public string $mediaType,
|
public string $mediaType,
|
||||||
public string $imdbId,
|
public string $imdbId,
|
||||||
|
public ?int $downloadId = null,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
@@ -21,14 +21,19 @@ readonly class DownloadMediaHandler implements HandlerInterface
|
|||||||
|
|
||||||
public function handle(CommandInterface $command): ResultInterface
|
public function handle(CommandInterface $command): ResultInterface
|
||||||
{
|
{
|
||||||
$download = $this->downloadRepository->insert(
|
if (null === $command->downloadId) {
|
||||||
$command->url,
|
$download = $this->downloadRepository->insert(
|
||||||
$command->title,
|
$command->url,
|
||||||
$command->filename,
|
$command->title,
|
||||||
$command->imdbId,
|
$command->filename,
|
||||||
$command->mediaType,
|
$command->imdbId,
|
||||||
""
|
$command->mediaType,
|
||||||
);
|
""
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$download = $this->downloadRepository->find($command->downloadId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->downloadRepository->updateStatus($download->getId(), 'In Progress');
|
$this->downloadRepository->updateStatus($download->getId(), 'In Progress');
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ class DownloadMediaInput implements InputInterface
|
|||||||
|
|
||||||
#[SourceRequest('imdbId')]
|
#[SourceRequest('imdbId')]
|
||||||
public string $imdbId,
|
public string $imdbId,
|
||||||
|
|
||||||
|
public ?int $downloadId = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function toCommand(): CommandInterface
|
public function toCommand(): CommandInterface
|
||||||
@@ -35,6 +37,7 @@ class DownloadMediaInput implements InputInterface
|
|||||||
$this->filename,
|
$this->filename,
|
||||||
$this->mediaType,
|
$this->mediaType,
|
||||||
$this->imdbId,
|
$this->imdbId,
|
||||||
|
$this->downloadId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,13 @@
|
|||||||
<span class="w-4 inline-block text-center text-gray-50">{{ entity.progress }}</span>
|
<span class="w-4 inline-block text-center text-gray-50">{{ entity.progress }}</span>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr id="ad_download_{{ entity.id }}">
|
</tr>
|
||||||
|
</template>
|
||||||
|
</turbo-stream>
|
||||||
|
|
||||||
|
<turbo-stream action="prepend" target="alert_list">
|
||||||
|
<template>
|
||||||
|
<twig:Alert title="Success" message="{{ entity.title }} has been added to the Download queue" alert_id="{{ entity.id }}" data-controller="alert" />
|
||||||
</template>
|
</template>
|
||||||
</turbo-stream>
|
</turbo-stream>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -20,16 +26,14 @@
|
|||||||
{% if entity.status != "Complete" %}
|
{% if entity.status != "Complete" %}
|
||||||
<turbo-stream action="update" target="ad_download_{{ id }}">
|
<turbo-stream action="update" target="ad_download_{{ id }}">
|
||||||
<template>
|
<template>
|
||||||
<tr id="ad_download_{{ entity.id }}">
|
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-stone-800 min-w-[45ch] max-w-[45ch] truncate">
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-stone-800 min-w-[45ch] max-w-[45ch] truncate">
|
{{ entity.title }}
|
||||||
{{ entity.title }}
|
</td>
|
||||||
</td>
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-end text-gray-800 dark:text-gray-50">
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-end text-gray-800 dark:text-gray-50">
|
<span class="p-1.5 bg-purple-600 rounded-full">
|
||||||
<span class="p-1.5 bg-purple-600 rounded-full">
|
<span class="w-4 inline-block text-center text-gray-50">{{ entity.progress }}</span>
|
||||||
<span class="w-4 inline-block text-center text-gray-50">{{ entity.progress }}</span>
|
</span>
|
||||||
</span>
|
</td>
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</template>
|
</template>
|
||||||
</turbo-stream>
|
</turbo-stream>
|
||||||
{% else %}
|
{% else %}
|
||||||
@@ -42,18 +46,20 @@
|
|||||||
</template>
|
</template>
|
||||||
</turbo-stream>
|
</turbo-stream>
|
||||||
|
|
||||||
{# <turbo-stream action="prepend" target="complete_downloads_list">#}
|
<turbo-stream action="prepend" target="recent_downloads">
|
||||||
{# <template>#}
|
<template>
|
||||||
{# <div class="result_group download-item" id="cd_download_{{ entity.id }}">#}
|
<tr id="recent_download_{{ entity.id }}">
|
||||||
{# <div class="title">{{ entity.title }}</div>#}
|
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-stone-800 min-w-[45ch] max-w-[45ch] truncate">
|
||||||
{# <div class="filename">{{ entity.filename }}</div>#}
|
{{ entity.title }}
|
||||||
{# <div class="status">#}
|
</td>
|
||||||
{# <span class="pill {{ status_color_map[entity.status] }} status-badge">{{ entity.status }}</span>#}
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-end text-gray-800 dark:text-gray-50">
|
||||||
{# <span class="pill progress">{{ entity.progress }}%</span>#}
|
<span class="p-1.5 bg-purple-600 rounded-full">
|
||||||
{# </div>#}
|
<span class="w-4 inline-block text-center text-gray-50">{{ entity.progress }}</span>
|
||||||
{# </div>#}
|
</span>
|
||||||
{# </template>#}
|
</td>
|
||||||
{# </turbo-stream>#}
|
</tr>
|
||||||
|
</template>
|
||||||
|
</turbo-stream>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div{{ attributes }} class="min-w-48">
|
<div{{ attributes }} class="min-w-48">
|
||||||
<table class="divide-y divide-gray-200 dark:divide-gray-50 dark:bg-gray-50 table-fixed" {{ turbo_stream_listen('App\\Download\\Framework\\Entity\\Download') }}>
|
<table id="active_downloads" class="divide-y divide-gray-200 dark:divide-gray-50 dark:bg-gray-50 table-fixed" {{ turbo_stream_listen('App\\Download\\Framework\\Entity\\Download') }}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="dark:bg-gray-50">
|
<tr class="dark:bg-gray-50">
|
||||||
<th scope="col"
|
<th scope="col"
|
||||||
@@ -20,9 +20,9 @@
|
|||||||
{{ download.title }}
|
{{ download.title }}
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-end text-gray-800 dark:text-gray-50">
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-end text-gray-800 dark:text-gray-50">
|
||||||
<span class="p-1.5 bg-purple-600 rounded-full">
|
<span class="p-1.5 bg-purple-600 rounded-full">
|
||||||
<span class="w-4 inline-block text-center text-gray-50">{{ download.progress }}</span>
|
<span class="w-4 inline-block text-center text-gray-50">{{ download.progress }}</span>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
</twig:Card>
|
</twig:Card>
|
||||||
|
|
||||||
<twig:Card title="Recent Downloads" class="w-full">
|
<twig:Card title="Recent Downloads" class="w-full">
|
||||||
<table class="divide-y divide-gray-200 dark:divide-gray-50 dark:bg-gray-50 table-fixed">
|
<table id="recent_downloads" class="divide-y divide-gray-200 dark:divide-gray-50 dark:bg-gray-50 table-fixed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="dark:bg-gray-50">
|
<tr class="dark:bg-gray-50">
|
||||||
<th scope="col"
|
<th scope="col"
|
||||||
|
|||||||
Reference in New Issue
Block a user