41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from board_mate_client import ApiClient, DefaultApi, GameDto, MoveDto
|
|
|
|
|
|
class ApiController:
|
|
|
|
def __init__(self, config) -> None:
|
|
self.config = config
|
|
|
|
def create_party(self, white_name, black_name, time_value, increment) -> str | None:
|
|
try:
|
|
with ApiClient(self.config) as client:
|
|
api = DefaultApi(client)
|
|
game = GameDto(
|
|
white_name=white_name,
|
|
black_name=black_name,
|
|
time_value=time_value,
|
|
increment=increment
|
|
)
|
|
response = api.create_party(game)
|
|
print("Raw response:", response)
|
|
return str(response.data)
|
|
except Exception as e:
|
|
print("Error during create_party:", e)
|
|
return None
|
|
|
|
def retrieve_game(self, game_id) -> GameDto:
|
|
with ApiClient(self.config) as client:
|
|
api = DefaultApi(client)
|
|
response = api.retrieve_games(game_id)
|
|
return GameDto.from_dict(response.data)
|
|
|
|
def add_move(self, game_id, notation) -> str:
|
|
with ApiClient(self.config) as client:
|
|
api = DefaultApi(client)
|
|
|
|
move = MoveDto(
|
|
notation=notation,
|
|
)
|
|
|
|
response = api.add_move(game_id, move)
|
|
return str(response.data) |