/**
  * @param Uuid $id
  * @return BookReadModel
  * @throws NotFoundHttpException
  */
 private function getBook(Uuid $id)
 {
     try {
         return $this->bookService->getBook($id);
     } catch (ObjectNotFoundException $e) {
         throw new NotFoundHttpException($e->getMessage(), $e);
     }
 }
 /**
  * @Rest\Post("",
  *  condition="request.headers.get('content-type') matches '/domain-model=add-book/i'"
  * )
  * @Rest\View(statusCode=201)
  *
  * @ParamConverter("bookResource",
  *  class="AppBundle\Controller\Resource\Book",
  *  converter="fos_rest.request_body"
  * )
  *
  * @param BookResource $bookResource
  * @return View
  * @throws HttpException
  */
 public function addBookAction(BookResource $bookResource)
 {
     $id = Uuid::createNew();
     $authors = array_map(function (AuthorResource $author) use($id) {
         return new AddAuthor($id, $author->getFirstName(), $author->getLastName(), -1);
     }, $bookResource->getAuthors());
     $command = new AddBook($id, $authors, $bookResource->getTitle(), $bookResource->getISBN());
     $this->commandBus->send($command);
     $book = $this->bookService->getBook($id);
     return $this->viewBuilder->setDocument($book)->setVersion()->setLocation(static::BASE_ROUTE . $book->getId())->build();
 }
 public function testBookIsAvailableAfterBookAdded()
 {
     $bookId = Uuid::createNew();
     $title = 'foo';
     $isbn = 'bar';
     $firstName = 'bar';
     $lastName = 'baz';
     $authors = [new AuthorAdded($bookId, $firstName, $lastName)];
     $storage = new MemoryStorage();
     $service = new BookService($storage);
     $service->on(new BookAdded($bookId, $authors, $title, $isbn));
     $book = $service->getBook($bookId);
     self::assertEquals($bookId, $book->getId());
     self::assertEquals($title, $book->getTitle());
     self::assertTrue($book->isAvailable());
     foreach ($book->getAuthors()->getIterator() as $author) {
         /* @var $author Author */
         self::assertEquals($firstName, $author->getFirstName());
         self::assertEquals($lastName, $author->getLastName());
     }
 }