Commit a3cb7b33 authored by Johan Vervloet's avatar Johan Vervloet
Browse files

Reopen trick: api, #184

parent 05d50d94
......@@ -10,6 +10,7 @@ use App\Domain\ValueObject\Player\PlayerIdentifier;
use App\Domain\ValueObject\Secret;
use App\Domain\WriteModel\Game\Command\PickUpCard;
use App\Domain\WriteModel\Game\Command\PlayCard;
use App\Domain\WriteModel\Game\Command\ReopenTrick;
use App\Domain\WriteModel\Game\Command\ReviewPreviousTrick;
use App\Domain\WriteModel\Game\Command\VoteAsWinner;
use App\Domain\WriteModel\Game\GameIdentifier;
......@@ -159,4 +160,21 @@ final class TrickApiController extends AbstractController
return new JsonResponse(null, Response::HTTP_NO_CONTENT);
}
/**
* @Route("/api/game/{gameId}/winner/{trickNumber}/vote/{playerSecret}", name="wdebelek.api.reopen_trick", methods="DELETE", options={"expose"=true})
*/
public function reopenTrick(
string $gameId,
string $playerSecret,
int $trickNumber
): Response {
$this->commandBus->dispatch(
new ReopenTrick(
GameIdentifier::fromString($gameId),
PlayerIdentifier::withSecret(Secret::fromString($playerSecret)),
$trickNumber
)
);
}
}
<?php
declare(strict_types=1);
namespace App\Domain\WriteModel\Game\Command;
use App\Domain\ValueObject\Player\PlayerIdentifier;
use App\Domain\WriteModel\Game\GameIdentifier;
use RvaVzw\KrakBoem\Cqrs\CommandBus\Command;
final class ReopenTrick implements Command
{
public function __construct(
private GameIdentifier $gameIdentifier,
private PlayerIdentifier $reopeningPlayer,
private int $trickNumber,
) {
}
public function getGameIdentifier(): GameIdentifier
{
return $this->gameIdentifier;
}
public function getReopeningPlayer(): PlayerIdentifier
{
return $this->reopeningPlayer;
}
public function getTrickNumber(): int
{
return $this->trickNumber;
}
}
<?php
declare(strict_types=1);
namespace App\Domain\WriteModel\Game\Command;
use App\Domain\WriteModel\Game\Game;
final class ReopenTrickHandler extends AbstractGameCommandHandler
{
public function __invoke(ReopenTrick $command): void
{
/** @var Game $game */
$game = $this->gameRepository->get($command->getGameIdentifier());
$game->reopenTrick(
$command->getReopeningPlayer(),
$command->getTrickNumber()
);
$this->gameRepository->save($game);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment