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:
parent
7fe4ac0d3b
commit
37e1b202c2
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\CommandHandler;
|
||||
|
||||
use App\Domain\Manga\Application\Command\DeleteChapter;
|
||||
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
|
||||
use App\Domain\Shared\Domain\Contract\CommandHandlerInterface;
|
||||
use App\Domain\Shared\Domain\Contract\CommandInterface;
|
||||
|
||||
readonly class DeleteChapterHandler implements CommandHandlerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ChapterRepositoryInterface $chapterRepository
|
||||
) {}
|
||||
|
||||
public function handle(CommandInterface $command): void
|
||||
{
|
||||
assert($command instanceof DeleteChapter);
|
||||
|
||||
$chapter = $this->chapterRepository->findVisibleById($command->chapterId);
|
||||
|
||||
if (!$chapter) {
|
||||
throw new ChapterNotFoundException($command->chapterId);
|
||||
}
|
||||
|
||||
// Soft delete by setting isVisible to false
|
||||
$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(),
|
||||
false, // isVisible = false (soft delete)
|
||||
$chapter->isAvailable(),
|
||||
$chapter->getCreatedAt()
|
||||
);
|
||||
|
||||
$this->chapterRepository->save($updatedChapter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user