コード例 #1
0
ファイル: Book.php プロジェクト: EightArmCode/librarian
 /**
  * @param ReadModel $book
  * @return Book
  */
 public static function createFromReadModel(ReadModel $book)
 {
     $authors = array_map(function (AuthorReadModel $author) {
         return Author::createFromReadModel($author);
     }, iterator_to_array($book->getAuthors()->getIterator()));
     return new self($book->getId()->getValue(), $authors, $book->getTitle(), $book->getISBN(), $book->isAvailable());
 }
コード例 #2
0
 public function testAddAuthorActionSendsAddAuthorCommand()
 {
     $this->commandBus->expects(self::once())->method('send')->will(self::returnCallback(function (Command $command) {
         self::assertInstanceOf(AddAuthor::class, $command);
     }));
     $id = Uuid::createNew();
     $book = new Book($id, new Authors(), 'title', 'isbn', true, -1);
     $this->service->expects(self::atLeastOnce())->method('getBook')->will(self::returnValue($book));
     $author = new Author('first', 'last');
     $resource = AuthorResource::createFromReadModel($author);
     $controller = new BooksController($this->viewBuilder, $this->service, $this->commandBus);
     $controller->addAuthorAction($id, $resource, -1);
 }
コード例 #3
0
 /**
  * @Rest\Put("/{id}/author",
  *  condition="request.headers.get('content-type') matches '/domain-model=add-author/i'",
  *  requirements={
  *      "id"="[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}"
  *  },
  *  defaults={
  *      "id"=null
  *  }
  * )
  * @Rest\View()
  *
  * @ParamConverter("id",
  *  class="AppBundle\EventSourcing\EventStore\Uuid",
  *  converter="param_converter"
  * )
  * @ParamConverter("author",
  *  class="AppBundle\Controller\Resource\Book\Author",
  *  converter="fos_rest.request_body"
  * )
  * @ParamConverter("version",
  *  class="AppBundle\Domain\ReadModel\Book",
  *  options={
  *      "id": "id",
  *  },
  *  converter="param_converter"
  * )
  *
  * @param Uuid $id
  * @param AuthorResource $author
  * @param integer $version
  * @return View
  * @throws HttpException
  */
 public function addAuthorAction(Uuid $id, AuthorResource $author, $version)
 {
     $command = new AddAuthor($id, $author->getFirstName(), $author->getLastName(), $version);
     $this->commandBus->send($command);
     $updatedBook = $this->bookService->getBook($id);
     return $this->viewBuilder->setDocument($updatedBook)->setVersion()->setLocation(static::BASE_ROUTE . $updatedBook->getId())->build();
 }