diff --git a/composer.json b/composer.json index d1c72f9..574e4af 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,7 @@ "symfony/string": " 6.1.*", "symfony/translation": " 6.1.*", "symfony/twig-bundle": " 6.1.*", + "symfony/uid": " 6.1.*", "symfony/validator": " 6.1.*", "symfony/web-link": " 6.1.*", "symfony/yaml": " 6.1.*", diff --git a/composer.lock b/composer.lock index 50f7c54..f5719d8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3782904a5950ea216badb0d03761a762", + "content-hash": "1bfc4cd53ff6415f1246ad7cbdab8353", "packages": [ { "name": "composer/package-versions-deprecated", @@ -6299,6 +6299,88 @@ ], "time": "2022-05-10T07:21:04+00:00" }, + { + "name": "symfony/polyfill-uuid", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-uuid.git", + "reference": "f3cf1a645c2734236ed1e2e671e273eeb3586166" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/f3cf1a645c2734236ed1e2e671e273eeb3586166", + "reference": "f3cf1a645c2734236ed1e2e671e273eeb3586166", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-uuid": "*" + }, + "suggest": { + "ext-uuid": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Uuid\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Grégoire Pineau", + "email": "lyrixx@lyrixx.info" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for uuid functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "uuid" + ], + "support": { + "source": "https://github.com/symfony/polyfill-uuid/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, { "name": "symfony/process", "version": "v6.1.3", @@ -7821,6 +7903,80 @@ ], "time": "2022-05-27T16:55:36+00:00" }, + { + "name": "symfony/uid", + "version": "v6.1.11", + "source": { + "type": "git", + "url": "https://github.com/symfony/uid.git", + "reference": "7c53913df24517eb5e0fab4caf294e84fcecc277" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/uid/zipball/7c53913df24517eb5e0fab4caf294e84fcecc277", + "reference": "7c53913df24517eb5e0fab4caf294e84fcecc277", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-uuid": "^1.15" + }, + "require-dev": { + "symfony/console": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Uid\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Grégoire Pineau", + "email": "lyrixx@lyrixx.info" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an object-oriented API to generate and represent UIDs", + "homepage": "https://symfony.com", + "keywords": [ + "UID", + "ulid", + "uuid" + ], + "support": { + "source": "https://github.com/symfony/uid/tree/v6.1.11" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-01-01T08:36:55+00:00" + }, { "name": "symfony/validator", "version": "v6.1.5", diff --git a/config/doctrine/orm/Dinosaur.orm.xml b/config/doctrine/orm/Dinosaur.orm.xml index e1f769d..eec174e 100644 --- a/config/doctrine/orm/Dinosaur.orm.xml +++ b/config/doctrine/orm/Dinosaur.orm.xml @@ -10,9 +10,7 @@ table="dinosaur" > - - - + diff --git a/config/doctrine/orm/Species.orm.xml b/config/doctrine/orm/Species.orm.xml index 100370d..dbaa335 100644 --- a/config/doctrine/orm/Species.orm.xml +++ b/config/doctrine/orm/Species.orm.xml @@ -10,9 +10,7 @@ table="species" > - - - + diff --git a/config/packages/messenger.yaml b/config/packages/messenger.yaml index 66e6802..697a115 100644 --- a/config/packages/messenger.yaml +++ b/config/packages/messenger.yaml @@ -28,4 +28,4 @@ framework: routing: 'App\Message\Food\Consume': async_low_priority 'App\Message\Food\Refill': async_high_priority - 'App\Event\Event': async_low_priority + 'App\Event\AsyncLowPriorityEvent': async_low_priority diff --git a/migrations/Version20230217084031.php b/migrations/Version20230217084031.php new file mode 100644 index 0000000..7e08774 --- /dev/null +++ b/migrations/Version20230217084031.php @@ -0,0 +1,37 @@ +addSql('ALTER TABLE dinosaur DROP FOREIGN KEY FK_DAEDC56EB2A1D860'); + $this->addSql('ALTER TABLE dinosaur CHANGE id id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', CHANGE species_id species_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\''); + $this->addSql('ALTER TABLE species CHANGE id id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\''); + $this->addSql('ALTER TABLE dinosaur ADD CONSTRAINT FK_DAEDC56EB2A1D860 FOREIGN KEY (species_id) REFERENCES species (id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE dinosaur DROP FOREIGN KEY FK_DAEDC56EB2A1D860'); + $this->addSql('ALTER TABLE dinosaur CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE species_id species_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE species CHANGE id id INT AUTO_INCREMENT NOT NULL'); + $this->addSql('ALTER TABLE dinosaur ADD CONSTRAINT FK_DAEDC56EB2A1D860 FOREIGN KEY (species_id) REFERENCES species (id)'); + } +} diff --git a/src/Command/ConsumeCommand.php b/src/Command/ConsumeCommand.php index 63d4a03..3c55025 100644 --- a/src/Command/ConsumeCommand.php +++ b/src/Command/ConsumeCommand.php @@ -39,7 +39,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $dinosaur = $dinosaurs[$randomDinoKey]; - $consumeMessage = new Consume($dinosaur->getId(), $dinosaur->getName()); + $consumeMessage = new Consume( + $dinosaur->getId()->toRfc4122(), + $dinosaur->getName() + ); $this->bus->dispatch($consumeMessage); } diff --git a/src/Controller/DinosaursController.php b/src/Controller/DinosaursController.php index da10a5f..48dff13 100644 --- a/src/Controller/DinosaursController.php +++ b/src/Controller/DinosaursController.php @@ -50,7 +50,7 @@ public function list(Request $request, ManagerRegistry $doctrine): Response #[Route( '/dinosaurs/{id}', name: 'app_single_dinosaur', - requirements: ['id' => '\d+'] + requirements: ['id' => '^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$'] )] public function single(string $id, ManagerRegistry $doctrine): Response { @@ -71,7 +71,7 @@ public function single(string $id, ManagerRegistry $doctrine): Response } #[Route('/dinosaurs/create', name: 'app_create_dinosaur')] - public function create(Request $request, ManagerRegistry $doctrine): Response + public function create(Request $request): Response { $form = $this->createForm(DinosaurType::class); @@ -105,9 +105,9 @@ public function create(Request $request, ManagerRegistry $doctrine): Response #[Route( '/dinosaurs/{id}/edit', name: 'app_edit_dinosaur', - requirements: ['id' => '\d+'] + requirements: ['id' => '^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$'] )] - public function edit(Request $request, int $id, ManagerRegistry $doctrine): Response + public function edit(Request $request, string $id, ManagerRegistry $doctrine): Response { $dinosaur = $doctrine ->getRepository(Dinosaur::class) @@ -149,9 +149,9 @@ public function edit(Request $request, int $id, ManagerRegistry $doctrine): Resp #[Route( '/dinosaurs/{id}/remove', name: 'app_remove_dinosaur', - requirements: ['id' => '\d+'] + requirements: ['id' => '^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$'] )] - public function remove(int $id): Response + public function remove(string $id): Response { $this->bus->dispatch(new Delete($id)); diff --git a/src/Controller/SpeciesController.php b/src/Controller/SpeciesController.php index 9f32c39..9a54c46 100644 --- a/src/Controller/SpeciesController.php +++ b/src/Controller/SpeciesController.php @@ -66,9 +66,9 @@ public function create(Request $request, ManagerRegistry $doctrine): Response #[Route( '/species/{id}/edit', name: 'app_edit_species', - requirements: ['id' => '\d+'] + requirements: ['id' => '^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$'] )] - public function edit(Request $request, int $id, ManagerRegistry $doctrine): Response + public function edit(Request $request, string $id, ManagerRegistry $doctrine): Response { $species = $doctrine ->getRepository(Species::class) @@ -108,9 +108,9 @@ public function edit(Request $request, int $id, ManagerRegistry $doctrine): Resp #[Route( '/species/{id}/remove', name: 'app_remove_species', - requirements: ['id' => '\d+'] + requirements: ['id' => '^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$'] )] - public function remove(int $id): Response + public function remove(string $id): Response { $this->bus->dispatch(new Delete($id)); diff --git a/src/Entity/Dinosaur.php b/src/Entity/Dinosaur.php index 74b7bea..43643e4 100644 --- a/src/Entity/Dinosaur.php +++ b/src/Entity/Dinosaur.php @@ -2,9 +2,11 @@ namespace App\Entity; +use Symfony\Component\Uid\Uuid; + class Dinosaur { - private int $id; + private ?Uuid $id; private string $name; private string $gender; private Species $species; @@ -18,8 +20,10 @@ public function __construct( Species $species, int $age, string $eyesColor, - Park $park + Park $park, + ?Uuid $id = null ) { + $this->id = $id ?? Uuid::v4(); $this->name = $name; $this->gender = $gender; $this->species = $species; @@ -28,11 +32,16 @@ public function __construct( $this->park = $park; } - public function getId(): int + public function getId(): ?Uuid { return $this->id; } + public function setId(?Uuid $id): void + { + $this->id = $id; + } + public function getName(): string { return $this->name; diff --git a/src/Entity/Species.php b/src/Entity/Species.php index 3a958fd..c49d2a3 100644 --- a/src/Entity/Species.php +++ b/src/Entity/Species.php @@ -4,10 +4,11 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Symfony\Component\Uid\Uuid; class Species { - private int $id; + private ?Uuid $id; private string $name; private array $habitats; private string $feeding; @@ -17,18 +18,25 @@ public function __construct( string $name, array $habitats, string $feeding, + ?Uuid $id = null ) { + $this->id = $id ?? Uuid::v4(); $this->name = $name; $this->habitats = $habitats; $this->feeding = $feeding; $this->dinosaurs = new ArrayCollection(); } - public function getId(): int + public function getId(): ?Uuid { return $this->id; } + public function setId(?Uuid $id): void + { + $this->id = $id; + } + public function getName(): string { return $this->name; diff --git a/src/Event/AbstractEvent.php b/src/Event/AbstractEvent.php index 4408c2e..be3b76e 100644 --- a/src/Event/AbstractEvent.php +++ b/src/Event/AbstractEvent.php @@ -4,14 +4,14 @@ namespace App\Event; -class AbstractEvent implements Event +class AbstractEvent { public function __construct( - private int $id + private string $id ) { } - public function getAggregateRootId(): int + public function getId(): string { return $this->id; } diff --git a/src/Event/AsyncLowPriorityEvent.php b/src/Event/AsyncLowPriorityEvent.php new file mode 100644 index 0000000..e9ba284 --- /dev/null +++ b/src/Event/AsyncLowPriorityEvent.php @@ -0,0 +1,9 @@ +indexer->delete($event->getAggregateRootId()); + $this->indexer->delete($event->getId()); } } diff --git a/src/EventHandler/Dinosaur/UpsertDinosaurSummary.php b/src/EventHandler/Dinosaur/UpsertDinosaurSummary.php index d161064..3500455 100644 --- a/src/EventHandler/Dinosaur/UpsertDinosaurSummary.php +++ b/src/EventHandler/Dinosaur/UpsertDinosaurSummary.php @@ -26,31 +26,31 @@ public function __construct( #[AsMessageHandler] public function handleDinosaurHasBeenCreated(DinosaurHasBeenCreated $event): void { - $this->updateSummaryByDinosaur($event->getAggregateRootId()); + $this->updateSummaryByDinosaur($event->getId()); } #[AsMessageHandler] public function handleDinosaurHasBeenUpdated(DinosaurHasBeenUpdated $event): void { - $this->updateSummaryByDinosaur($event->getAggregateRootId()); + $this->updateSummaryByDinosaur($event->getId()); } #[AsMessageHandler] public function handleFoodHasBeenConsumed(HasBeenConsumed $event): void { - $this->updateSummariesByPark($event->getAggregateRootId()); + $this->updateSummariesByPark((int) $event->getId()); } #[AsMessageHandler] public function handleFoodHasBeenRefilled(HasBeenRefilled $event): void { - $this->updateSummariesByPark($event->getAggregateRootId()); + $this->updateSummariesByPark((int) $event->getId()); } #[AsMessageHandler] public function handleSpeciesHasBeenUpdated(SpeciesHasBeenUpdated $event): void { - $speciesId = $event->getAggregateRootId(); + $speciesId = $event->getId(); $species = $this ->speciesRepository->find($speciesId); @@ -68,7 +68,7 @@ public function handleSpeciesHasBeenUpdated(SpeciesHasBeenUpdated $event): void } } - private function updateSummaryByDinosaur(int $dinosaurId): void + private function updateSummaryByDinosaur(string $dinosaurId): void { $dinosaur = $this->dinosaurRepository->find($dinosaurId); diff --git a/src/EventListener/WorkerListener.php b/src/EventListener/WorkerListener.php index 5a82e5e..088f6a9 100644 --- a/src/EventListener/WorkerListener.php +++ b/src/EventListener/WorkerListener.php @@ -59,6 +59,10 @@ public function onWorkerMessageHandledEvent(WorkerMessageHandledEvent $event) $handledStamp = $envelope->last(HandledStamp::class); + if (null === $handledStamp) { + return; + } + $handlerName = $handledStamp->getHandlerName(); $message = $envelope->getMessage(); diff --git a/src/Form/Type/DinosaurType.php b/src/Form/Type/DinosaurType.php index 919a461..4a617b0 100644 --- a/src/Form/Type/DinosaurType.php +++ b/src/Form/Type/DinosaurType.php @@ -8,7 +8,6 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ColorType; -use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; diff --git a/src/Indexer.php b/src/Indexer.php index 80be302..f115818 100644 --- a/src/Indexer.php +++ b/src/Indexer.php @@ -37,7 +37,7 @@ public function indexFromDinosaur(Dinosaur $dinosaur): void ]); } - public function delete(int $id) + public function delete(string $id) { $this->client->delete([ 'index' => self::INDEX_NAME, diff --git a/src/Message/Dinosaur/Create.php b/src/Message/Dinosaur/Create.php index 5ccc485..7190c94 100644 --- a/src/Message/Dinosaur/Create.php +++ b/src/Message/Dinosaur/Create.php @@ -9,7 +9,7 @@ public function __construct( public readonly string $gender, public readonly string $eyesColor, public readonly int $age, - public readonly int $speciesId, + public readonly string $speciesId, public readonly int $parkId, ) { } diff --git a/src/Message/Dinosaur/Delete.php b/src/Message/Dinosaur/Delete.php index 4bbd29d..941dfc2 100644 --- a/src/Message/Dinosaur/Delete.php +++ b/src/Message/Dinosaur/Delete.php @@ -5,7 +5,7 @@ class Delete { public function __construct( - public readonly int $id + public readonly string $id ) { } } diff --git a/src/Message/Dinosaur/Edit.php b/src/Message/Dinosaur/Edit.php index fb6102a..88e2c9c 100644 --- a/src/Message/Dinosaur/Edit.php +++ b/src/Message/Dinosaur/Edit.php @@ -5,12 +5,12 @@ class Edit { public function __construct( - public readonly int $id, + public readonly string $id, public readonly string $name, public readonly string $gender, public readonly string $eyesColor, public readonly int $age, - public readonly int $speciesId + public readonly string $speciesId ) { } } diff --git a/src/Message/Food/Consume.php b/src/Message/Food/Consume.php index 336f2ac..8cb8dda 100644 --- a/src/Message/Food/Consume.php +++ b/src/Message/Food/Consume.php @@ -9,7 +9,7 @@ class Consume implements Lockable { public function __construct( - public readonly int $dinosaurId, + public readonly string $dinosaurId, public readonly string $dinosaurName ) { } diff --git a/src/Message/Species/Delete.php b/src/Message/Species/Delete.php index b0b40ef..578beae 100644 --- a/src/Message/Species/Delete.php +++ b/src/Message/Species/Delete.php @@ -5,7 +5,7 @@ class Delete { public function __construct( - public readonly int $id + public readonly string $id ) { } } diff --git a/src/Message/Species/Edit.php b/src/Message/Species/Edit.php index 911c931..5fb840c 100644 --- a/src/Message/Species/Edit.php +++ b/src/Message/Species/Edit.php @@ -5,7 +5,7 @@ class Edit { public function __construct( - public readonly int $id, + public readonly string $id, public readonly string $name, public readonly string $feeding, public readonly array $habitats diff --git a/src/MessageHandler/Dinosaur/Create.php b/src/MessageHandler/Dinosaur/Create.php index 209a671..fa1da30 100644 --- a/src/MessageHandler/Dinosaur/Create.php +++ b/src/MessageHandler/Dinosaur/Create.php @@ -47,15 +47,13 @@ public function __invoke(CreateMessage $message) $this->dinosaurRepository->add($dino); - $id = $this->dinosaurRepository->findNextId(); - - $envelop = new Envelope(new HasBeenCreated($id)); + $envelop = new Envelope(new HasBeenCreated($dino->getId()->toRfc4122())); $this ->eventBus ->dispatch($envelop->with(new DispatchAfterCurrentBusStamp())) ; - return new CreateMessageResult($id); + return new CreateMessageResult($dino->getId()->toRfc4122()); } } diff --git a/src/MessageHandler/Dinosaur/Edit.php b/src/MessageHandler/Dinosaur/Edit.php index fba67d5..aa2862a 100644 --- a/src/MessageHandler/Dinosaur/Edit.php +++ b/src/MessageHandler/Dinosaur/Edit.php @@ -2,12 +2,10 @@ namespace App\MessageHandler\Dinosaur; -use App\Entity\Dinosaur; -use App\Entity\Species; use App\Event\Dinosaur\HasBeenUpdated; use App\Message\Dinosaur\Edit as EditMessage; -use App\MessageResults\Dinosaur\Edit as EditOutput; -use Doctrine\ORM\EntityManagerInterface; +use App\Repository\DinosaurRepository; +use App\Repository\SpeciesRepository; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Messenger\Envelope; @@ -19,20 +17,18 @@ final class Edit { public function __construct( private MessageBusInterface $eventBus, - private EntityManagerInterface $entityManager + private DinosaurRepository $dinosaurRepository, + private SpeciesRepository $speciesRepository, ) { } public function __invoke(EditMessage $message) { - $dinosaurRepository = $this->entityManager->getRepository(Dinosaur::class); - $speciesRepository = $this->entityManager->getRepository(Species::class); - - if (!$dinosaur = $dinosaurRepository->find($message->id)) { + if (!$dinosaur = $this->dinosaurRepository->find($message->id)) { throw new NotFoundHttpException("Dinosaur with id {$message->id} not found"); } - if (!$species = $speciesRepository->find($message->speciesId)) { + if (!$species = $this->speciesRepository->find($message->speciesId)) { throw new NotFoundHttpException("Species with id {$message->id} not found"); } @@ -41,7 +37,7 @@ public function __invoke(EditMessage $message) $dinosaur->setAge($message->age); $dinosaur->setSpecies($species); - $envelop = new Envelope(new HasBeenUpdated($dinosaur->getId())); + $envelop = new Envelope(new HasBeenUpdated($dinosaur->getId()->toRfc4122())); $this ->eventBus diff --git a/src/MessageHandler/Food/Consume.php b/src/MessageHandler/Food/Consume.php index ee83770..39912d4 100644 --- a/src/MessageHandler/Food/Consume.php +++ b/src/MessageHandler/Food/Consume.php @@ -54,7 +54,7 @@ public function __invoke(FoodConsume $message) $park->setFoodAmount($park->getFoodAmount() - $consumedAmout); - $envelop = new Envelope(new HasBeenConsumed($park->getId())); + $envelop = new Envelope(new HasBeenConsumed((string) $park->getId())); $this ->eventBus diff --git a/src/MessageHandler/Food/Refill.php b/src/MessageHandler/Food/Refill.php index 952c546..d5772a2 100644 --- a/src/MessageHandler/Food/Refill.php +++ b/src/MessageHandler/Food/Refill.php @@ -43,7 +43,7 @@ public function __invoke(FoodRefill $refill) $park->setFoodAmount(100); } - $envelop = new Envelope(new HasBeenRefilled($park->getId())); + $envelop = new Envelope(new HasBeenRefilled((string) $park->getId())); $this ->eventBus diff --git a/src/MessageHandler/Species/Create.php b/src/MessageHandler/Species/Create.php index a4f7db1..f4a426b 100644 --- a/src/MessageHandler/Species/Create.php +++ b/src/MessageHandler/Species/Create.php @@ -7,11 +7,11 @@ use App\Message\Species\Create as CreateMessage; use App\MessageResults\Species\Create as CreateMessageResult; use App\Repository\SpeciesRepository; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp; +use Symfony\Component\Uid\Uuid; #[AsMessageHandler] final class Create @@ -30,17 +30,17 @@ public function __invoke(CreateMessage $message): CreateMessageResult feeding: $message->feeding ); - $this->speciesRepository->persist($species); + $this->speciesRepository->add($species); - $id = $this->speciesRepository->findNextId(); - - $envelop = new Envelope(new HasBeenCreated($id)); + $envelop = new Envelope(new HasBeenCreated( + $species->getId()->toRfc4122() + )); $this ->eventBus ->dispatch($envelop->with(new DispatchAfterCurrentBusStamp())) ; - return new CreateMessageResult($id); + return new CreateMessageResult($species->getId()->toRfc4122()); } } diff --git a/src/Stamp/LockStamp.php b/src/Stamp/LockStamp.php index 587381d..26aee5e 100644 --- a/src/Stamp/LockStamp.php +++ b/src/Stamp/LockStamp.php @@ -7,7 +7,7 @@ class LockStamp implements StampInterface { public function __construct( - public readonly int $lockKey + public readonly string $lockKey ) { } }