Files
Mangarr/src/Domain/Manga/Application/CommandHandler/DeleteChapterHandler.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

32 lines
1.0 KiB
PHP

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