fix: game service api block when a game is running
This commit is contained in:
@@ -25,8 +25,8 @@ class PokerRequestHandler(BaseHTTPRequestHandler):
|
||||
if path == ["games"]:
|
||||
self._json({"games": MANAGER.list_games()})
|
||||
return
|
||||
if len(path) == 2 and path[0] == "games":
|
||||
self._json(MANAGER.get_game(path[1]).to_dict())
|
||||
if len(path) == 2 and path[0] in {"game", "games"}:
|
||||
self._json(MANAGER.get_game_state(path[1]))
|
||||
return
|
||||
self._json({"error": "not found"}, HTTPStatus.NOT_FOUND)
|
||||
except KeyError as exc:
|
||||
@@ -35,11 +35,11 @@ class PokerRequestHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self) -> None:
|
||||
path = self._path_parts()
|
||||
try:
|
||||
if path == ["games"]:
|
||||
if path in (["game"], ["games"]):
|
||||
game = MANAGER.create_game(self._read_json())
|
||||
self._json(game.to_dict(), HTTPStatus.CREATED)
|
||||
self._json(game.snapshot_completed(), HTTPStatus.CREATED)
|
||||
return
|
||||
if len(path) == 3 and path[0] == "games" and path[2] == "hands":
|
||||
if len(path) == 3 and path[0] in {"game", "games"} and path[2] == "hands":
|
||||
body = self._read_json()
|
||||
count = int(body.get("count", 1))
|
||||
until_one_left = bool(body.get("until_one_left", False))
|
||||
@@ -51,9 +51,9 @@ class PokerRequestHandler(BaseHTTPRequestHandler):
|
||||
small_blind=small_blind,
|
||||
big_blind=big_blind,
|
||||
)
|
||||
self._json({"hands": summaries, "game": MANAGER.get_game(path[1]).to_dict()})
|
||||
self._json({"hands": summaries, "game": MANAGER.get_game_state(path[1])})
|
||||
return
|
||||
if len(path) == 4 and path[0] == "games" and path[2] == "hands" and path[3] == "run":
|
||||
if len(path) == 4 and path[0] in {"game", "games"} and path[2] == "hands" and path[3] == "run":
|
||||
body = self._read_json()
|
||||
count = int(body.get("count", 1))
|
||||
until_one_left = bool(body.get("until_one_left", False))
|
||||
@@ -65,7 +65,7 @@ class PokerRequestHandler(BaseHTTPRequestHandler):
|
||||
small_blind=small_blind,
|
||||
big_blind=big_blind,
|
||||
)
|
||||
self._json({"hands": summaries, "game": MANAGER.get_game(path[1]).to_dict()})
|
||||
self._json({"hands": summaries, "game": MANAGER.get_game_state(path[1])})
|
||||
return
|
||||
self._json({"error": "not found"}, HTTPStatus.NOT_FOUND)
|
||||
except KeyError as exc:
|
||||
|
||||
Reference in New Issue
Block a user