Skip to content

Commit

Permalink
Implementing ACID Transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
yceruto committed Dec 27, 2023
1 parent 87fbbf6 commit 0c151cb
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 10 deletions.
6 changes: 5 additions & 1 deletion config/packages/messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
'messenger' => [
'default_bus' => 'command.bus',
'buses' => [
'command.bus' => [],
'command.bus' => [
'middleware' => [
'messenger.middleware.doctrine_transaction',
],
],
'query.bus' => [],
],
'transports' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public function __invoke(AnonymizeBooksCommand $command): void
$book->update(
author: new Author($command->anonymizedName),
);

$this->bookRepository->save($book);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final readonly class CreateBookCommandHandler implements CommandHandlerInterface
{
public function __construct(private readonly BookRepositoryInterface $bookRepository)
public function __construct(private BookRepositoryInterface $bookRepository)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ public function __invoke(DiscountBookCommand $command): void
}

$book->applyDiscount($command->discount);

$this->bookRepository->save($book);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function __invoke(UpdateBookCommand $command): Book
price: $command->price,
);

$this->bookRepository->save($book);

return $book;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public function __construct(EntityManagerInterface $em)
public function save(Book $book): void
{
$this->em->persist($book);
$this->em->flush();
}

public function remove(Book $book): void
{
$this->em->remove($book);
$this->em->flush();
}

public function ofId(BookId $id): ?Book
Expand Down

0 comments on commit 0c151cb

Please sign in to comment.