- 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>
38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Manga\Application\CommandHandler;
|
|
|
|
use App\Domain\Manga\Application\Command\EditMultipleChapters;
|
|
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
|
|
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
|
|
|
|
readonly class EditMultipleChaptersHandler
|
|
{
|
|
public function __construct(
|
|
private MangaRepositoryInterface $mangaRepository
|
|
) {}
|
|
|
|
public function handle(EditMultipleChapters $command): void
|
|
{
|
|
foreach ($command->chapters as $chapterData) {
|
|
$chapter = $this->mangaRepository->findChapterById($chapterData->id);
|
|
|
|
if (!$chapter) {
|
|
throw new ChapterNotFoundException($chapterData->id);
|
|
}
|
|
|
|
$manga = $this->mangaRepository->findById($chapter->getMangaId()->getValue());
|
|
|
|
if ($chapterData->title !== null) {
|
|
$manga->updateChapterTitle($chapter, $chapterData->title);
|
|
}
|
|
|
|
if ($chapterData->volume !== null) {
|
|
$manga->updateChapterVolume($chapter, $chapterData->volume);
|
|
}
|
|
|
|
$this->mangaRepository->save($manga);
|
|
}
|
|
}
|
|
}
|