[Chapter7] Improvements

This commit is contained in:
Carlos Buenosvinos
2022-03-01 09:03:33 +01:00
parent d0875d3aed
commit 57ea79c1f4
2 changed files with 7 additions and 11 deletions

View File

@@ -18,8 +18,8 @@ use Cheeper\Chapter7\DomainModel\Cheep\CheepRepository;
final class PostCheepCommandHandler
{
public function __construct(
private AuthorRepository $authors,
private CheepRepository $cheeps,
private AuthorRepository $authorRepository,
private CheepRepository $cheepRepository,
private EventBus $eventBus
) {
}
@@ -30,11 +30,11 @@ final class PostCheepCommandHandler
$cheepId = CheepId::fromString($command->cheepId());
$message = CheepMessage::write($command->message());
$author = $this->authors->ofId($authorId);
$author = $this->authorRepository->ofId($authorId);
$this->checkAuthorExists($author, $authorId);
$cheep = Cheep::compose($authorId, $cheepId, $message);
$this->cheeps->add($cheep);
$this->cheepRepository->add($cheep);
$this->eventBus->notifyAll($cheep->domainEvents());
}

View File

@@ -8,10 +8,10 @@ use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Cheep\CheepDate;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\AllChapters\DomainModel\Cheep\CheepMessage;
use Cheeper\AllChapters\DomainModel\Clock;
use Cheeper\Chapter7\Application\MessageTrait;
use Cheeper\Chapter7\DomainModel\DomainEvent;
use DateTimeImmutable;
use DateTimeZone;
// snippet cheep-posted-domain-event
final class CheepPosted implements DomainEvent
@@ -35,9 +35,7 @@ final class CheepPosted implements DomainEvent
$cheep->authorId()->toString(),
$cheep->cheepMessage()->message(),
$cheep->cheepDate()->date(),
new DateTimeImmutable(
timezone: new DateTimeZone("UTC")
)
Clock::instance()->now()
);
}
@@ -53,9 +51,7 @@ final class CheepPosted implements DomainEvent
$authorId->toString(),
$cheepMessage->message(),
$cheepDate->date(),
new DateTimeImmutable(
timezone: new DateTimeZone("UTC")
)
Clock::instance()->now()
);
}