[Chapter 7] Clean up unnecessary level
This commit is contained in:
@@ -10,6 +10,8 @@ use Redis;
|
||||
//snippet create-followers-counter-projection-projector
|
||||
final class CreateFollowersCounterProjectionHandler implements CreateFollowersCounterProjectionHandlerInterface
|
||||
{
|
||||
public const REDIS_KEY_TEMPLATE = 'author_followers_counter_projection:%s';
|
||||
|
||||
public function __construct(
|
||||
private Redis $redis
|
||||
) {
|
||||
@@ -26,7 +28,10 @@ final class CreateFollowersCounterProjectionHandler implements CreateFollowersCo
|
||||
];
|
||||
|
||||
$this->redis->set(
|
||||
'author_followers_counter_projection:'.$authorId->toString(),
|
||||
sprintf(
|
||||
self::REDIS_KEY_TEMPLATE,
|
||||
$authorId->toString()
|
||||
),
|
||||
json_encode($result)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Cheeper\Chapter7\Application\Cheep\Projection;
|
||||
|
||||
use Cheeper\Chapter7\Application\Author\Projection\CreateFollowersCounterProjectionHandler;
|
||||
use Redis;
|
||||
|
||||
//snippet add-cheep-to-timeline-projector
|
||||
@@ -17,13 +18,26 @@ final class AddCheepToTimelineProjectionHandler
|
||||
public function __invoke(AddCheepToTimelineProjection $message): void
|
||||
{
|
||||
$this->redis->lPush(
|
||||
sprintf("timelines_%s", $message->authorId),
|
||||
json_encode([
|
||||
'cheep_id' => $message->cheepId,
|
||||
'cheep_message' => $message->cheepMessage,
|
||||
'cheep_date' => $message->cheepDate,
|
||||
], JSON_THROW_ON_ERROR)
|
||||
$this->getRedisKey($message),
|
||||
$this->getRedisContent($message)
|
||||
);
|
||||
}
|
||||
|
||||
private function getRedisKey(AddCheepToTimelineProjection $message): string
|
||||
{
|
||||
return sprintf(
|
||||
CreateFollowersCounterProjectionHandler::REDIS_KEY_TEMPLATE,
|
||||
$message->authorId
|
||||
);
|
||||
}
|
||||
|
||||
private function getRedisContent(AddCheepToTimelineProjection $message): string
|
||||
{
|
||||
return json_encode([
|
||||
'cheep_id' => $message->cheepId,
|
||||
'cheep_message' => $message->cheepMessage,
|
||||
'cheep_date' => $message->cheepDate,
|
||||
], JSON_THROW_ON_ERROR);
|
||||
}
|
||||
}
|
||||
//end-snippet
|
||||
|
||||
Reference in New Issue
Block a user