Skip to content

Commit 13092e7

Browse files
committed
Expose OpenGame
1 parent 800495e commit 13092e7

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"doctrine/doctrine-migrations-bundle": "^3.3",
3737
"doctrine/migrations": "^3.7",
3838
"doctrine/orm": "^3.0",
39-
"gaming-platform/api": "dev-add-game-messages",
39+
"gaming-platform/api": "dev-add-game-messages#3da446b",
4040
"jms/serializer": "^3.17",
4141
"marein/php-nchan-client": "^3.1",
4242
"marein/symfony-lock-doctrine-migrations-bundle": "^1.0",

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/connect-four/services/consumer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
arguments:
55
- 'ConnectFour.GameRequests'
66
- 'gaming'
7-
- ['ConnectFour.JoinGame', 'ConnectFour.MakeMove', 'ConnectFour.GetGamesByPlayer']]
7+
- ['ConnectFour.OpenGame', 'ConnectFour.JoinGame', 'ConnectFour.MakeMove', 'ConnectFour.GetGamesByPlayer']
88
tags: [{ name: 'gaming.message-broker.topology' }]
99

1010
connect-four.game-requests-message-handler.consumer:

src/ConnectFour/Port/Adapter/Messaging/GameRequestsMessageHandler.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Gaming\Common\MessageBroker\MessageHandler;
1111
use Gaming\ConnectFour\Application\Game\Command\JoinCommand;
1212
use Gaming\ConnectFour\Application\Game\Command\MoveCommand;
13+
use Gaming\ConnectFour\Application\Game\Command\OpenCommand;
1314
use Gaming\ConnectFour\Application\Game\Query\GamesByPlayerQuery;
1415
use Gaming\ConnectFour\Application\Game\Query\Model\Game\Game;
1516
use Gaming\ConnectFour\Application\Game\Query\Model\Game\Move;
@@ -20,6 +21,7 @@
2021
use GamingPlatform\Api\ConnectFour\V1\GetGamesByPlayerResponse;
2122
use GamingPlatform\Api\ConnectFour\V1\JoinGameResponse;
2223
use GamingPlatform\Api\ConnectFour\V1\MakeMoveResponse;
24+
use GamingPlatform\Api\ConnectFour\V1\OpenGameResponse;
2325

2426
final class GameRequestsMessageHandler implements MessageHandler
2527
{
@@ -32,13 +34,36 @@ public function __construct(
3234
public function handle(Message $message, Context $context): void
3335
{
3436
match ($message->name()) {
37+
'ConnectFour.OpenGame' => $this->handleOpenGame($message, $context),
3538
'ConnectFour.JoinGame' => $this->handleJoinGame($message, $context),
3639
'ConnectFour.MakeMove' => $this->handleMakeMove($message, $context),
3740
'ConnectFour.GetGamesByPlayer' => $this->handleGetGamesByPlayer($message, $context),
3841
default => true
3942
};
4043
}
4144

45+
private function handleOpenGame(Message $message, Context $context): void
46+
{
47+
$request = ConnectFourV1Factory::createOpenGame($message->body());
48+
49+
$response = $this->commandBus->handle(
50+
new OpenCommand(
51+
$request->getPlayerId(),
52+
$request->getWidth(),
53+
$request->getHeight(),
54+
$request->getStone(),
55+
$request->getTimer()
56+
)
57+
);
58+
59+
$context->reply(
60+
new Message(
61+
'ConnectFour.OpenGameResponse',
62+
new OpenGameResponse()->setGameId($response)->serializeToString()
63+
)
64+
);
65+
}
66+
4267
private function handleJoinGame(Message $message, Context $context): void
4368
{
4469
$request = ConnectFourV1Factory::createJoinGame($message->body());

0 commit comments

Comments
 (0)