feat: event listener sur MangaCreated pour ajouter les chapitres à la création

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-11 18:28:30 +01:00
parent 879b8fa2dc
commit 73774f84ff
10 changed files with 83 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\CreateManga;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Contract\Service\ImageProcessorInterface;
use App\Domain\Manga\Domain\Event\MangaCreated;
use App\Domain\Manga\Domain\Model\Manga;
use App\Domain\Manga\Domain\Model\ValueObject\ExternalId;
use App\Domain\Manga\Domain\Model\ValueObject\ImageUrls;
@@ -12,12 +13,14 @@ use App\Domain\Manga\Domain\Model\ValueObject\MangaId;
use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug;
use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Messenger\MessageBusInterface;
readonly class CreateMangaHandler
{
public function __construct(
private MangaRepositoryInterface $mangaRepository,
private ImageProcessorInterface $imageProcessor
private ImageProcessorInterface $imageProcessor,
private MessageBusInterface $messageBus
) {}
public function handle(CreateManga $command): void
@@ -47,5 +50,9 @@ readonly class CreateMangaHandler
}
$this->mangaRepository->save($manga);
if ($command->externalId) {
$this->messageBus->dispatch(new MangaCreated($command->externalId));
}
}
}