55use Application \Form \Type \DinosaurType ;
66use Application \Form \Type \SearchType ;
77use Application \MessageBus \CommandBus ;
8+ use Application \MessageBus \EventBus ;
89use Application \MessageBus \QueryBus ;
10+ use Domain \Event \DinosaurIsBorn ;
911use Domain \Exception \DinosaurNotFoundException ;
1012use Domain \Query \GetSingleDinosaur ;
1113use Domain \Query \GetAllDinosaurs ;
@@ -22,7 +24,8 @@ final class DinosaursController extends AbstractController
2224{
2325 public function __construct (
2426 private CommandBus $ commandBus ,
25- private QueryBus $ queryBus
27+ private QueryBus $ queryBus ,
28+ private EventBus $ eventBus
2629 ) {
2730 }
2831
@@ -55,12 +58,10 @@ public function list(Request $request): Response
5558 )]
5659 public function single (string $ id ): Response
5760 {
58- $ dinosaur = $ this
59- ->dinosaursCollection
60- ->find ($ id );
61-
62- if (false === $ dinosaur ) {
63- throw $ this ->createNotFoundException ('The dinosaur you are looking for does not exists. ' );
61+ try {
62+ $ dinosaur = $ this ->queryBus ->dispatch (new GetSingleDinosaur \Query ($ id ));
63+ } catch (DinosaurNotFoundException $ e ) {
64+ throw $ this ->createNotFoundException ();
6465 }
6566
6667 return $ this ->render ('dinosaur.html.twig ' , [
0 commit comments