Files
Mangarr/src/Domain/Manga/Application/CommandHandler/DeleteCbzHandler.php
ext.jeremy.guillot@maxicoffee.domains 2c051351a8 refactor(manga): Chapter entité DDD de Manga + AggregateRoot
- Ajoute AggregateRoot dans Shared (domain events + pull pattern)
- Manga extends AggregateRoot, devient vrai aggregate root DDD
- Chapter passe de readonly à entité mutable avec MangaId VO
- Manga expose les méthodes domaine pour toute mutation de chapitre :
  addChapter, updateChapterTitle/Volume/Pages, hideChapter, removeChapterPages
- Supprime saveChapter/updateChapter/deleteChapter de MangaRepositoryInterface
- save(Manga) gère désormais la persistance des chapitres via pull pattern
- Tous les handlers/listeners passent par l'agrégat (plus d'accès direct)
- phparkitect autorise AggregateRoot dans les couches Domain

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 19:15:11 +01:00

39 lines
1.3 KiB
PHP

<?php
namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\DeleteCbz;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
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 MangaRepositoryInterface $mangaRepository,
private FileServiceInterface $fileService
) {}
public function handle(CommandInterface $command): void
{
assert($command instanceof DeleteCbz);
$chapter = $this->mangaRepository->findVisibleChapterById($command->chapterId);
if (!$chapter) {
throw new ChapterNotFoundException($command->chapterId);
}
if (!$chapter->isAvailable()) {
throw new CbzFileNotFoundException($command->chapterId);
}
$manga = $this->mangaRepository->findById($chapter->getMangaId()->getValue());
$manga->removeChapterPages($chapter);
$this->mangaRepository->save($manga);
}
}