fix: adds download record at time of download
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -15,5 +15,6 @@ class DownloadMediaCommand implements CommandInterface
|
||||
public string $filename,
|
||||
public string $mediaType,
|
||||
public string $imdbId,
|
||||
public ?int $downloadId = null,
|
||||
) {}
|
||||
}
|
||||
@@ -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');
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user