[Chapter7] Improvements
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user