From b8a25bc3cc2a1717a7f63e46121794a50e71226f Mon Sep 17 00:00:00 2001 From: Markus Reinhold Date: Thu, 8 Aug 2024 07:03:56 +0200 Subject: [PATCH] Remove redundant abstractions WebInterface now invokes the application layers directly. That's okay, because the bus interface already abstracts the other contexts, so there is no reason to put another layer in between, especially because the type information would be lost through this additional layer. --- config/chat/services/chat.yml | 4 - config/connect-four/services/game.yml | 4 - config/identity/services/user.yml | 4 - config/web-interface/services/console.yml | 2 +- config/web-interface/services/controller.yml | 8 +- config/web-interface/services/integration.yml | 12 -- config/web-interface/services/security.yml | 2 +- src/Chat/Presentation/Http/ChatController.php | 59 ------ .../Game/Query/Model/Game/Game.php | 5 + .../Game/Query/Model/OpenGames/OpenGame.php | 22 +-- .../Port/Adapter/Http/GameController.php | 178 ------------------ .../Repository/PredisOpenGameStore.php | 4 +- .../Port/Adapter/Http/UserController.php | 52 ----- src/WebInterface/Application/ChatService.php | 18 -- .../Application/ConnectFourService.php | 53 ------ .../Application/IdentityService.php | 21 --- .../DirectControllerInvocationChatService.php | 65 ------- ...ControllerInvocationConnectFourService.php | 132 ------------- ...ectControllerInvocationIdentityService.php | 52 ----- .../Security/ArrivalAuthenticator.php | 7 +- ...PublishRunningGamesCountToNchanCommand.php | 7 +- .../Presentation/Http/ChatController.php | 25 ++- .../Http/ConnectFourController.php | 41 ++-- .../Presentation/Http/PageController.php | 20 +- .../Presentation/Http/SignupController.php | 28 +-- .../Presentation/Http/View/game.html.twig | 6 +- .../Presentation/Http/View/lobby.html.twig | 2 +- .../Presentation/Http/View/profile.html.twig | 2 +- 28 files changed, 103 insertions(+), 732 deletions(-) delete mode 100644 src/Chat/Presentation/Http/ChatController.php delete mode 100644 src/ConnectFour/Port/Adapter/Http/GameController.php delete mode 100644 src/Identity/Port/Adapter/Http/UserController.php delete mode 100644 src/WebInterface/Application/ChatService.php delete mode 100644 src/WebInterface/Application/ConnectFourService.php delete mode 100644 src/WebInterface/Application/IdentityService.php delete mode 100644 src/WebInterface/Infrastructure/Integration/DirectControllerInvocationChatService.php delete mode 100644 src/WebInterface/Infrastructure/Integration/DirectControllerInvocationConnectFourService.php delete mode 100644 src/WebInterface/Infrastructure/Integration/DirectControllerInvocationIdentityService.php diff --git a/config/chat/services/chat.yml b/config/chat/services/chat.yml index dd55deb5..5eb7c3c8 100644 --- a/config/chat/services/chat.yml +++ b/config/chat/services/chat.yml @@ -1,8 +1,4 @@ services: - chat.chat-controller: - class: Gaming\Chat\Presentation\Http\ChatController - arguments: ['@chat.command-bus', '@chat.query-bus'] - chat.chat-gateway: class: Gaming\Chat\Infrastructure\DoctrineChatGateway arguments: ['@chat.doctrine-dbal', 'chat', 'message'] diff --git a/config/connect-four/services/game.yml b/config/connect-four/services/game.yml index c2f1063f..6fbb4a56 100644 --- a/config/connect-four/services/game.yml +++ b/config/connect-four/services/game.yml @@ -1,8 +1,4 @@ services: - connect-four.game-controller: - class: Gaming\ConnectFour\Port\Adapter\Http\GameController - arguments: ['@connect-four.command-bus', '@connect-four.query-bus'] - connect-four.game-repository: class: Gaming\ConnectFour\Port\Adapter\Persistence\Repository\DoctrineJsonGameRepository arguments: diff --git a/config/identity/services/user.yml b/config/identity/services/user.yml index 483ef567..335e1e28 100644 --- a/config/identity/services/user.yml +++ b/config/identity/services/user.yml @@ -1,8 +1,4 @@ services: - identity.user-controller: - class: Gaming\Identity\Port\Adapter\Http\UserController - arguments: ['@identity.command-bus'] - identity.user-repository: class: Gaming\Identity\Port\Adapter\Persistence\Repository\DoctrineUserRepository arguments: ['@identity.doctrine-orm'] diff --git a/config/web-interface/services/console.yml b/config/web-interface/services/console.yml index 01f27604..c11171a5 100644 --- a/config/web-interface/services/console.yml +++ b/config/web-interface/services/console.yml @@ -1,6 +1,6 @@ services: Gaming\WebInterface\Presentation\Console\PublishRunningGamesCountToNchanCommand: - arguments: ['@web-interface.connect-four-service', '@web-interface.browser-notifier'] + arguments: ['@connect-four.query-bus', '@web-interface.browser-notifier'] tags: - name: console.command command: web-interface:publish-running-games-count-to-nchan diff --git a/config/web-interface/services/controller.yml b/config/web-interface/services/controller.yml index d3d786d1..a837cda6 100644 --- a/config/web-interface/services/controller.yml +++ b/config/web-interface/services/controller.yml @@ -1,7 +1,7 @@ services: web-interface.page-controller: class: Gaming\WebInterface\Presentation\Http\PageController - arguments: ['@twig', '@web-interface.connect-four-service', '@web-interface.security'] + arguments: ['@twig', '@connect-four.query-bus', '@web-interface.security'] tags: ['controller.service_arguments'] web-interface.signup-controller: @@ -9,7 +9,7 @@ services: arguments: - '@uri_signer' - '@web-interface.security' - - '@web-interface.identity-service' + - '@identity.command-bus' - '@gaming.form-violation-mapper' calls: [[setContainer, ['@Psr\Container\ContainerInterface']]] tags: ['controller.service_arguments', 'container.service_subscriber'] @@ -28,10 +28,10 @@ services: web-interface.chat-controller: class: Gaming\WebInterface\Presentation\Http\ChatController - arguments: ['@web-interface.chat-service', '@web-interface.security'] + arguments: ['@chat.command-bus', '@chat.query-bus', '@web-interface.security'] tags: ['controller.service_arguments'] web-interface.connect-four-controller: class: Gaming\WebInterface\Presentation\Http\ConnectFourController - arguments: ['@web-interface.connect-four-service', '@web-interface.security'] + arguments: ['@connect-four.command-bus', '@web-interface.security'] tags: ['controller.service_arguments'] diff --git a/config/web-interface/services/integration.yml b/config/web-interface/services/integration.yml index 91f4a56f..68ef3ec8 100644 --- a/config/web-interface/services/integration.yml +++ b/config/web-interface/services/integration.yml @@ -1,16 +1,4 @@ services: - web-interface.chat-service: - class: Gaming\WebInterface\Infrastructure\Integration\DirectControllerInvocationChatService - arguments: ['@chat.chat-controller'] - - web-interface.connect-four-service: - class: Gaming\WebInterface\Infrastructure\Integration\DirectControllerInvocationConnectFourService - arguments: ['@connect-four.game-controller'] - - web-interface.identity-service: - class: Gaming\WebInterface\Infrastructure\Integration\DirectControllerInvocationIdentityService - arguments: ['@identity.user-controller'] - web-interface.nchan: class: Marein\Nchan\Nchan arguments: diff --git a/config/web-interface/services/security.yml b/config/web-interface/services/security.yml index e4034386..bae26081 100644 --- a/config/web-interface/services/security.yml +++ b/config/web-interface/services/security.yml @@ -9,4 +9,4 @@ services: web-interface.security.arrival_authenticator: class: Gaming\WebInterface\Infrastructure\Security\ArrivalAuthenticator - arguments: ['@web-interface.identity-service', '@security.token_storage'] + arguments: ['@identity.command-bus', '@security.token_storage'] diff --git a/src/Chat/Presentation/Http/ChatController.php b/src/Chat/Presentation/Http/ChatController.php deleted file mode 100644 index 66b0e305..00000000 --- a/src/Chat/Presentation/Http/ChatController.php +++ /dev/null @@ -1,59 +0,0 @@ -commandBus = $commandBus; - $this->queryBus = $queryBus; - } - - public function writeMessageAction(Request $request): JsonResponse - { - $chatId = (string)$request->query->get('chatId'); - - $this->commandBus->handle( - new WriteMessageCommand( - $chatId, - (string)$request->request->get('authorId'), - (string)$request->request->get('message') - ) - ); - - return new JsonResponse( - [ - 'chatId' => $chatId - ] - ); - } - - public function messagesAction(Request $request): JsonResponse - { - return new JsonResponse( - $this->queryBus->handle( - new MessagesQuery( - (string)$request->query->get('chatId'), - (string)$request->query->get('authorId'), - (int)$request->query->get('offset'), - (int)$request->query->get('limit') - ) - ) - ); - } -} diff --git a/src/ConnectFour/Application/Game/Query/Model/Game/Game.php b/src/ConnectFour/Application/Game/Query/Model/Game/Game.php index 6a99f639..139027f3 100644 --- a/src/ConnectFour/Application/Game/Query/Model/Game/Game.php +++ b/src/ConnectFour/Application/Game/Query/Model/Game/Game.php @@ -56,6 +56,11 @@ public function id(): string return $this->gameId; } + public function chatId(): string + { + return $this->chatId; + } + public function finished(): bool { return $this->finished; diff --git a/src/ConnectFour/Application/Game/Query/Model/OpenGames/OpenGame.php b/src/ConnectFour/Application/Game/Query/Model/OpenGames/OpenGame.php index 191713b0..5ca84725 100644 --- a/src/ConnectFour/Application/Game/Query/Model/OpenGames/OpenGame.php +++ b/src/ConnectFour/Application/Game/Query/Model/OpenGames/OpenGame.php @@ -6,23 +6,9 @@ final class OpenGame { - private string $gameId; - - private string $playerId; - - public function __construct(string $gameId, string $playerId) - { - $this->gameId = $gameId; - $this->playerId = $playerId; - } - - public function gameId(): string - { - return $this->gameId; - } - - public function playerId(): string - { - return $this->playerId; + public function __construct( + public readonly string $gameId, + public readonly string $playerId + ) { } } diff --git a/src/ConnectFour/Port/Adapter/Http/GameController.php b/src/ConnectFour/Port/Adapter/Http/GameController.php deleted file mode 100644 index 3babd096..00000000 --- a/src/ConnectFour/Port/Adapter/Http/GameController.php +++ /dev/null @@ -1,178 +0,0 @@ -queryBus->handle(new OpenGamesQuery()); - - $games = array_map( - static fn(OpenGame $openGame): array => [ - 'gameId' => $openGame->gameId(), - 'playerId' => $openGame->playerId() - ], - $openGames->games() - ); - - return new JsonResponse( - [ - 'games' => $games - ] - ); - } - - public function runningGamesAction(Request $request): JsonResponse - { - $runningGames = $this->queryBus->handle(new RunningGamesQuery()); - - return new JsonResponse( - [ - 'count' => $runningGames->count() - ] - ); - } - - public function gamesByPlayerAction(Request $request): JsonResponse - { - $gamesByPlayer = $this->queryBus->handle( - new GamesByPlayerQuery( - (string)$request->query->get('playerId') - ) - ); - - $games = array_map( - static fn(GameByPlayer $openGame): string => $openGame->gameId(), - $gamesByPlayer->games() - ); - - return new JsonResponse( - [ - 'games' => $games - ] - ); - } - - public function gameAction(Request $request): JsonResponse - { - $game = $this->queryBus->handle( - new GameQuery( - (string)$request->query->get('gameId') - ) - ); - - return new JsonResponse($game); - } - - public function openAction(Request $request): JsonResponse - { - $gameId = $this->commandBus->handle( - new OpenCommand( - (string)$request->request->get('playerId') - ) - ); - - return new JsonResponse( - [ - 'gameId' => $gameId - ] - ); - } - - public function joinAction(Request $request): JsonResponse - { - $gameId = (string)$request->query->get('gameId'); - - $this->commandBus->handle( - new JoinCommand( - $gameId, - (string)$request->request->get('playerId') - ) - ); - - return new JsonResponse( - [ - 'gameId' => $gameId - ] - ); - } - - public function abortAction(Request $request): JsonResponse - { - $gameId = (string)$request->query->get('gameId'); - - $this->commandBus->handle( - new AbortCommand( - $gameId, - (string)$request->request->get('playerId') - ) - ); - - return new JsonResponse( - [ - 'gameId' => $gameId - ] - ); - } - - public function resignAction(Request $request): JsonResponse - { - $gameId = (string)$request->query->get('gameId'); - - $this->commandBus->handle( - new ResignCommand( - $gameId, - (string)$request->request->get('playerId') - ) - ); - - return new JsonResponse( - [ - 'gameId' => $gameId - ] - ); - } - - public function moveAction(Request $request): JsonResponse - { - $gameId = (string)$request->query->get('gameId'); - - $this->commandBus->handle( - new MoveCommand( - $gameId, - (string)$request->request->get('playerId'), - (int)$request->request->get('column') - ) - ); - - return new JsonResponse( - [ - 'gameId' => $gameId - ] - ); - } -} diff --git a/src/ConnectFour/Port/Adapter/Persistence/Repository/PredisOpenGameStore.php b/src/ConnectFour/Port/Adapter/Persistence/Repository/PredisOpenGameStore.php index 77094e5a..5bc1d6d4 100644 --- a/src/ConnectFour/Port/Adapter/Persistence/Repository/PredisOpenGameStore.php +++ b/src/ConnectFour/Port/Adapter/Persistence/Repository/PredisOpenGameStore.php @@ -23,11 +23,11 @@ public function __construct( public function save(OpenGame $openGame): void { $this->predis->pipeline(function (ClientContextInterface $pipeline) use ($openGame): void { - $pipeline->set($this->storageKeyForGameInfo($openGame->gameId()), $openGame->playerId()); + $pipeline->set($this->storageKeyForGameInfo($openGame->gameId), $openGame->playerId); $pipeline->zadd( $this->storageKey, - [$openGame->gameId() => microtime(true)] + [$openGame->gameId => microtime(true)] ); }); } diff --git a/src/Identity/Port/Adapter/Http/UserController.php b/src/Identity/Port/Adapter/Http/UserController.php deleted file mode 100644 index a181c282..00000000 --- a/src/Identity/Port/Adapter/Http/UserController.php +++ /dev/null @@ -1,52 +0,0 @@ -commandBus->handle( - new ArriveCommand() - ); - - return new JsonResponse( - [ - 'userId' => $userId - ] - ); - } - - public function signUpAction(Request $request): JsonResponse - { - $userId = (string)$request->query->get('userId'); - - $this->commandBus->handle( - new SignUpCommand( - $userId, - (string)$request->request->get('email'), - (string)$request->request->get('username'), - $request->request->getBoolean('dryRun') - ) - ); - - return new JsonResponse( - [ - 'userId' => $userId - ] - ); - } -} diff --git a/src/WebInterface/Application/ChatService.php b/src/WebInterface/Application/ChatService.php deleted file mode 100644 index 053f34f1..00000000 --- a/src/WebInterface/Application/ChatService.php +++ /dev/null @@ -1,18 +0,0 @@ - - */ - public function writeMessage(string $chatId, string $authorId, string $message): array; - - /** - * @return array - */ - public function messages(string $chatId, string $authorId, int $offset, int $limit): array; -} diff --git a/src/WebInterface/Application/ConnectFourService.php b/src/WebInterface/Application/ConnectFourService.php deleted file mode 100644 index a9b69529..00000000 --- a/src/WebInterface/Application/ConnectFourService.php +++ /dev/null @@ -1,53 +0,0 @@ - - */ - public function openGames(): array; - - /** - * @return array - */ - public function runningGames(): array; - - /** - * @return array - */ - public function gamesByPlayer(string $playerId): array; - - /** - * @return array - */ - public function game(string $gameId): array; - - /** - * @return array - */ - public function open(string $playerId): array; - - /** - * @return array - */ - public function join(string $gameId, string $playerId): array; - - /** - * @return array - */ - public function abort(string $gameId, string $playerId): array; - - /** - * @return array - */ - public function resign(string $gameId, string $playerId): array; - - /** - * @return array - */ - public function move(string $gameId, string $playerId, int $column): array; -} diff --git a/src/WebInterface/Application/IdentityService.php b/src/WebInterface/Application/IdentityService.php deleted file mode 100644 index e244f16b..00000000 --- a/src/WebInterface/Application/IdentityService.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ - public function arrive(): array; - - /** - * @return array - * @throws ApplicationException - */ - public function signUp(string $userId, string $email, string $username, bool $dryRun = false): array; -} diff --git a/src/WebInterface/Infrastructure/Integration/DirectControllerInvocationChatService.php b/src/WebInterface/Infrastructure/Integration/DirectControllerInvocationChatService.php deleted file mode 100644 index a1c1ccb6..00000000 --- a/src/WebInterface/Infrastructure/Integration/DirectControllerInvocationChatService.php +++ /dev/null @@ -1,65 +0,0 @@ -chatController = $chatController; - } - - public function writeMessage(string $chatId, string $authorId, string $message): array - { - return $this->sendRequest( - 'writeMessage', - [ - 'chatId' => $chatId, - ], - [ - 'authorId' => $authorId, - 'message' => $message - ] - ); - } - - public function messages(string $chatId, string $authorId, int $offset, int $limit): array - { - return $this->sendRequest( - 'messages', - [ - 'chatId' => $chatId, - 'authorId' => $authorId, - 'offset' => $offset, - 'limit' => $limit - ] - ); - } - - /** - * @param array $queryParameter - * @param array $postParameter - * - * @return array - */ - private function sendRequest(string $actionName, array $queryParameter = [], array $postParameter = []): array - { - $method = $actionName . 'Action'; - - $response = $this->chatController->$method( - new Request($queryParameter, $postParameter) - ); - assert($response instanceof Response); - - return json_decode((string)$response->getContent(), true, 512, JSON_THROW_ON_ERROR); - } -} diff --git a/src/WebInterface/Infrastructure/Integration/DirectControllerInvocationConnectFourService.php b/src/WebInterface/Infrastructure/Integration/DirectControllerInvocationConnectFourService.php deleted file mode 100644 index 167f6826..00000000 --- a/src/WebInterface/Infrastructure/Integration/DirectControllerInvocationConnectFourService.php +++ /dev/null @@ -1,132 +0,0 @@ -gameController = $gameController; - } - - public function openGames(): array - { - return $this->sendRequest('openGames'); - } - - public function runningGames(): array - { - return $this->sendRequest('runningGames'); - } - - public function gamesByPlayer(string $playerId): array - { - return $this->sendRequest( - 'gamesByPlayer', - [ - 'playerId' => $playerId - ] - ); - } - - public function game(string $gameId): array - { - return $this->sendRequest( - 'game', - [ - 'gameId' => $gameId - ] - ); - } - - public function open(string $playerId): array - { - return $this->sendRequest( - 'open', - [], - [ - 'playerId' => $playerId - ] - ); - } - - public function join(string $gameId, string $playerId): array - { - return $this->sendRequest( - 'join', - [ - 'gameId' => $gameId - ], - [ - 'playerId' => $playerId - ] - ); - } - - public function abort(string $gameId, string $playerId): array - { - return $this->sendRequest( - 'abort', - [ - 'gameId' => $gameId - ], - [ - 'playerId' => $playerId - ] - ); - } - - public function resign(string $gameId, string $playerId): array - { - return $this->sendRequest( - 'resign', - [ - 'gameId' => $gameId - ], - [ - 'playerId' => $playerId - ] - ); - } - - public function move(string $gameId, string $playerId, int $column): array - { - return $this->sendRequest( - 'move', - [ - 'gameId' => $gameId - ], - [ - 'playerId' => $playerId, - 'column' => $column - ] - ); - } - - /** - * @param array $queryParameter - * @param array $postParameter - * - * @return array - */ - private function sendRequest(string $actionName, array $queryParameter = [], array $postParameter = []): array - { - $method = $actionName . 'Action'; - - $response = $this->gameController->$method( - new Request($queryParameter, $postParameter) - ); - assert($response instanceof Response); - - return json_decode((string)$response->getContent(), true, 512, JSON_THROW_ON_ERROR); - } -} diff --git a/src/WebInterface/Infrastructure/Integration/DirectControllerInvocationIdentityService.php b/src/WebInterface/Infrastructure/Integration/DirectControllerInvocationIdentityService.php deleted file mode 100644 index 99b173c6..00000000 --- a/src/WebInterface/Infrastructure/Integration/DirectControllerInvocationIdentityService.php +++ /dev/null @@ -1,52 +0,0 @@ -userController = $userController; - } - - public function arrive(): array - { - return $this->sendRequest('arrive'); - } - - public function signUp(string $userId, string $email, string $username, bool $dryRun = false): array - { - return $this->sendRequest( - 'signUp', - ['userId' => $userId], - ['email' => $email, 'username' => $username, 'dryRun' => $dryRun] - ); - } - - /** - * @param array $queryParameter - * @param array $postParameter - * - * @return array - */ - private function sendRequest(string $actionName, array $queryParameter = [], array $postParameter = []): array - { - $method = $actionName . 'Action'; - - $response = $this->userController->$method( - new Request($queryParameter, $postParameter) - ); - assert($response instanceof Response); - - return json_decode((string)$response->getContent(), true, 512, JSON_THROW_ON_ERROR); - } -} diff --git a/src/WebInterface/Infrastructure/Security/ArrivalAuthenticator.php b/src/WebInterface/Infrastructure/Security/ArrivalAuthenticator.php index c2a66d92..84a997d9 100644 --- a/src/WebInterface/Infrastructure/Security/ArrivalAuthenticator.php +++ b/src/WebInterface/Infrastructure/Security/ArrivalAuthenticator.php @@ -4,7 +4,8 @@ namespace Gaming\WebInterface\Infrastructure\Security; -use Gaming\WebInterface\Application\IdentityService; +use Gaming\Common\Bus\Bus; +use Gaming\Identity\Application\User\Command\ArriveCommand; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -18,7 +19,7 @@ final class ArrivalAuthenticator extends AbstractAuthenticator { public function __construct( - private readonly IdentityService $identityService, + private readonly Bus $identityCommandBus, private readonly TokenStorageInterface $tokenStorage ) { } @@ -36,7 +37,7 @@ public function authenticate(Request $request): Passport { return new SelfValidatingPassport( new UserBadge( - $this->identityService->arrive()['userId'] + $this->identityCommandBus->handle(new ArriveCommand()) ) ); } diff --git a/src/WebInterface/Presentation/Console/PublishRunningGamesCountToNchanCommand.php b/src/WebInterface/Presentation/Console/PublishRunningGamesCountToNchanCommand.php index 05dfd42f..5d4ecdd4 100644 --- a/src/WebInterface/Presentation/Console/PublishRunningGamesCountToNchanCommand.php +++ b/src/WebInterface/Presentation/Console/PublishRunningGamesCountToNchanCommand.php @@ -4,8 +4,9 @@ namespace Gaming\WebInterface\Presentation\Console; +use Gaming\Common\Bus\Bus; +use Gaming\ConnectFour\Application\Game\Query\RunningGamesQuery; use Gaming\WebInterface\Application\BrowserNotifier; -use Gaming\WebInterface\Application\ConnectFourService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -13,7 +14,7 @@ final class PublishRunningGamesCountToNchanCommand extends Command { public function __construct( - private readonly ConnectFourService $connectFourService, + private readonly Bus $connectFourQueryBus, private readonly BrowserNotifier $browserNotifier ) { parent::__construct(); @@ -24,7 +25,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $lastRunningGamesCount = -1; while (true) { - $currentRunningGamesCount = $this->connectFourService->runningGames()['count']; + $currentRunningGamesCount = $this->connectFourQueryBus->handle(new RunningGamesQuery())->count(); // Publish only if count has changed. if ($lastRunningGamesCount !== $currentRunningGamesCount) { diff --git a/src/WebInterface/Presentation/Http/ChatController.php b/src/WebInterface/Presentation/Http/ChatController.php index b90c785e..106ab1ec 100644 --- a/src/WebInterface/Presentation/Http/ChatController.php +++ b/src/WebInterface/Presentation/Http/ChatController.php @@ -4,7 +4,9 @@ namespace Gaming\WebInterface\Presentation\Http; -use Gaming\WebInterface\Application\ChatService; +use Gaming\Chat\Application\Command\WriteMessageCommand; +use Gaming\Chat\Application\Query\MessagesQuery; +use Gaming\Common\Bus\Bus; use Gaming\WebInterface\Infrastructure\Security\Security; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -12,31 +14,36 @@ final class ChatController { public function __construct( - private readonly ChatService $chatService, + private readonly Bus $chatCommandBus, + private readonly Bus $chatQueryBus, private readonly Security $security ) { } public function writeMessageAction(Request $request, string $chatId): JsonResponse { - return new JsonResponse( - $this->chatService->writeMessage( + $this->chatCommandBus->handle( + new WriteMessageCommand( $chatId, $this->security->getUser()->getUserIdentifier(), (string)$request->request->get('message') ) ); + + return new JsonResponse(); } public function messagesAction(Request $request, string $chatId): JsonResponse { return new JsonResponse( [ - 'messages' => $this->chatService->messages( - $chatId, - $this->security->getUser()->getUserIdentifier(), - 0, - 10000 + 'messages' => $this->chatQueryBus->handle( + new MessagesQuery( + $chatId, + $this->security->getUser()->getUserIdentifier(), + 0, + 10000 + ) ) ] ); diff --git a/src/WebInterface/Presentation/Http/ConnectFourController.php b/src/WebInterface/Presentation/Http/ConnectFourController.php index 57eb1fcf..9d98adbe 100644 --- a/src/WebInterface/Presentation/Http/ConnectFourController.php +++ b/src/WebInterface/Presentation/Http/ConnectFourController.php @@ -4,7 +4,12 @@ namespace Gaming\WebInterface\Presentation\Http; -use Gaming\WebInterface\Application\ConnectFourService; +use Gaming\Common\Bus\Bus; +use Gaming\ConnectFour\Application\Game\Command\AbortCommand; +use Gaming\ConnectFour\Application\Game\Command\JoinCommand; +use Gaming\ConnectFour\Application\Game\Command\MoveCommand; +use Gaming\ConnectFour\Application\Game\Command\OpenCommand; +use Gaming\ConnectFour\Application\Game\Command\ResignCommand; use Gaming\WebInterface\Infrastructure\Security\Security; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -12,7 +17,7 @@ final class ConnectFourController { public function __construct( - private readonly ConnectFourService $connectFourService, + private readonly Bus $connectFourCommandBus, private readonly Security $security ) { } @@ -20,50 +25,60 @@ public function __construct( public function openAction(Request $request): JsonResponse { return new JsonResponse( - $this->connectFourService->open( - $this->security->getUser()->getUserIdentifier() - ) + [ + 'gameId' => $this->connectFourCommandBus->handle( + new OpenCommand($this->security->getUser()->getUserIdentifier()) + ) + ] ); } public function joinAction(Request $request, string $gameId): JsonResponse { - return new JsonResponse( - $this->connectFourService->join( + $this->connectFourCommandBus->handle( + new JoinCommand( $gameId, $this->security->getUser()->getUserIdentifier() ) ); + + return new JsonResponse(); } public function abortAction(Request $request, string $gameId): JsonResponse { - return new JsonResponse( - $this->connectFourService->abort( + $this->connectFourCommandBus->handle( + new AbortCommand( $gameId, $this->security->getUser()->getUserIdentifier() ) ); + + return new JsonResponse(); } public function resignAction(Request $request, string $gameId): JsonResponse { - return new JsonResponse( - $this->connectFourService->resign( + $this->connectFourCommandBus->handle( + new ResignCommand( $gameId, $this->security->getUser()->getUserIdentifier() ) ); + + return new JsonResponse(); } public function moveAction(Request $request, string $gameId): JsonResponse { - return new JsonResponse( - $this->connectFourService->move( + $this->connectFourCommandBus->handle( + new MoveCommand( $gameId, $this->security->getUser()->getUserIdentifier(), (int)$request->request->get('column', -1) ) ); + + return new JsonResponse(); } } diff --git a/src/WebInterface/Presentation/Http/PageController.php b/src/WebInterface/Presentation/Http/PageController.php index c7acd310..d50c78f0 100644 --- a/src/WebInterface/Presentation/Http/PageController.php +++ b/src/WebInterface/Presentation/Http/PageController.php @@ -4,7 +4,11 @@ namespace Gaming\WebInterface\Presentation\Http; -use Gaming\WebInterface\Application\ConnectFourService; +use Gaming\Common\Bus\Bus; +use Gaming\ConnectFour\Application\Game\Query\GameQuery; +use Gaming\ConnectFour\Application\Game\Query\GamesByPlayerQuery; +use Gaming\ConnectFour\Application\Game\Query\OpenGamesQuery; +use Gaming\ConnectFour\Application\Game\Query\RunningGamesQuery; use Gaming\WebInterface\Infrastructure\Security\Security; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -14,7 +18,7 @@ final class PageController { public function __construct( private readonly Environment $twig, - private readonly ConnectFourService $connectFourService, + private readonly Bus $connectFourQueryBus, private readonly Security $security ) { } @@ -24,8 +28,8 @@ public function lobbyAction(): Response return new Response( $this->twig->render('@web-interface/lobby.html.twig', [ 'maximumNumberOfGamesInList' => 10, - 'openGames' => $this->connectFourService->openGames()['games'], - 'runningGames' => $this->connectFourService->runningGames(), + 'openGames' => $this->connectFourQueryBus->handle(new OpenGamesQuery()), + 'runningGames' => $this->connectFourQueryBus->handle(new RunningGamesQuery()), 'user' => $this->security->getUser() ]) ); @@ -35,7 +39,7 @@ public function gameAction(string $id): Response { return new Response( $this->twig->render('@web-interface/game.html.twig', [ - 'game' => $this->connectFourService->game($id), + 'game' => $this->connectFourQueryBus->handle(new GameQuery($id)), 'user' => $this->security->getUser() ]) ); @@ -45,9 +49,9 @@ public function profileAction(Request $request): Response { return new Response( $this->twig->render('@web-interface/profile.html.twig', [ - 'games' => $this->connectFourService->gamesByPlayer( - $this->security->getUser()->getUserIdentifier() - )['games'] + 'games' => $this->connectFourQueryBus->handle( + new GamesByPlayerQuery($this->security->getUser()->getUserIdentifier()) + )->games() ]) ); } diff --git a/src/WebInterface/Presentation/Http/SignupController.php b/src/WebInterface/Presentation/Http/SignupController.php index df0aaa0c..06e15e8c 100644 --- a/src/WebInterface/Presentation/Http/SignupController.php +++ b/src/WebInterface/Presentation/Http/SignupController.php @@ -4,9 +4,10 @@ namespace Gaming\WebInterface\Presentation\Http; +use Gaming\Common\Bus\Bus; use Gaming\Common\Bus\Exception\ApplicationException; use Gaming\Common\Bus\Integration\FormViolationMapper; -use Gaming\WebInterface\Application\IdentityService; +use Gaming\Identity\Application\User\Command\SignUpCommand; use Gaming\WebInterface\Infrastructure\Security\Security; use Gaming\WebInterface\Presentation\Http\Form\SignupType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -20,7 +21,7 @@ final class SignupController extends AbstractController public function __construct( private readonly UriSigner $uriSigner, private readonly Security $security, - private readonly IdentityService $identityService, + private readonly Bus $identityCommandBus, private readonly FormViolationMapper $formViolationMapper ) { } @@ -36,11 +37,13 @@ public function indexAction(Request $request): Response if ($form->isSubmitted() && $form->isValid()) { try { - $this->identityService->signUp( - $this->security->getUser()->getUserIdentifier(), - (string)$form->get('email')->getData(), - (string)$form->get('username')->getData(), - true + $this->identityCommandBus->handle( + new SignUpCommand( + $this->security->getUser()->getUserIdentifier(), + (string)$form->get('email')->getData(), + (string)$form->get('username')->getData(), + true + ) ); return $this->redirectToRoute('signup_verify_email', [ @@ -87,10 +90,13 @@ public function confirmAction(Request $request): Response if ($form->isSubmitted() && $form->isValid()) { try { - $this->identityService->signUp( - $this->security->getUser()->getUserIdentifier(), - (string)$form->get('email')->getData(), - (string)$form->get('username')->getData() + $this->identityCommandBus->handle( + new SignUpCommand( + $this->security->getUser()->getUserIdentifier(), + (string)$form->get('email')->getData(), + (string)$form->get('username')->getData(), + false + ) ); $this->security->getUser()->forceRefreshAtNextRequest(); diff --git a/src/WebInterface/Presentation/Http/View/game.html.twig b/src/WebInterface/Presentation/Http/View/game.html.twig index b1897083..136150f8 100644 --- a/src/WebInterface/Presentation/Http/View/game.html.twig +++ b/src/WebInterface/Presentation/Http/View/game.html.twig @@ -78,12 +78,12 @@
- + Abort
- + Resign
@@ -97,7 +97,7 @@ - {% endblock %} diff --git a/src/WebInterface/Presentation/Http/View/lobby.html.twig b/src/WebInterface/Presentation/Http/View/lobby.html.twig index ce0f4b2a..787a7889 100644 --- a/src/WebInterface/Presentation/Http/View/lobby.html.twig +++ b/src/WebInterface/Presentation/Http/View/lobby.html.twig @@ -19,7 +19,7 @@
- diff --git a/src/WebInterface/Presentation/Http/View/profile.html.twig b/src/WebInterface/Presentation/Http/View/profile.html.twig index 02648f61..576d8c31 100644 --- a/src/WebInterface/Presentation/Http/View/profile.html.twig +++ b/src/WebInterface/Presentation/Http/View/profile.html.twig @@ -7,7 +7,7 @@
{% for game in games %}

- + Anonymous - Anonymous