feat: ajout de la gestion des commandes pour la suppression des fichiers CBZ et des chapitres, avec création des gestionnaires et des ressources API correspondantes

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-06-29 18:33:33 +02:00
parent 7fe4ac0d3b
commit 37e1b202c2
42 changed files with 1413 additions and 21 deletions

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\DeleteCbz;
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
use App\Domain\Manga\Domain\Contract\Service\FileServiceInterface;
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
use App\Domain\Manga\Domain\Exception\CbzFileNotFoundException;
use App\Domain\Shared\Domain\Contract\CommandHandlerInterface;
use App\Domain\Shared\Domain\Contract\CommandInterface;
readonly class DeleteCbzHandler implements CommandHandlerInterface
{
public function __construct(
private ChapterRepositoryInterface $chapterRepository,
private FileServiceInterface $fileService
) {}
public function handle(CommandInterface $command): void
{
assert($command instanceof DeleteCbz);
$chapter = $this->chapterRepository->findVisibleById($command->chapterId);
if (!$chapter) {
throw new ChapterNotFoundException($command->chapterId);
}
// Check if chapter has a CBZ file
if (!$chapter->isAvailable()) {
throw new CbzFileNotFoundException($command->chapterId);
}
// Delete the physical CBZ file
// Note: We'll need to get the CBZ path from somewhere, likely from a legacy repository
// For now, we'll just mark the chapter as not available
// Update chapter to mark CBZ as not available
$updatedChapter = new \App\Domain\Manga\Domain\Model\Chapter(
new \App\Domain\Manga\Domain\Model\ValueObject\ChapterId($chapter->getId()),
$chapter->getMangaId(),
$chapter->getNumber(),
$chapter->getTitle(),
$chapter->getVolume(),
$chapter->isVisible(),
false, // isAvailable = false (CBZ removed)
$chapter->getCreatedAt()
);
$this->chapterRepository->save($updatedChapter);
}
}