From 499639823e9002c83e50cb19ddc796c25679d7d3 Mon Sep 17 00:00:00 2001 From: Laurent Date: Sun, 14 Dec 2025 23:13:39 +0100 Subject: [PATCH] Fix move quoting --- .../controllers/GameController.java | 5 +- .../controllers/dtos/MoveDto.java | 13 +++ rpi/api-resources/board-mate.yaml | 12 ++- rpi/board_mate_client/__init__.py | 1 + rpi/board_mate_client/api/default_api.py | 31 +++---- rpi/board_mate_client/models/__init__.py | 1 + rpi/board_mate_client/models/move_dto.py | 87 +++++++++++++++++++ rpi/controllers/board_mate_controller.py | 25 ++++-- rpi/main.py | 31 ++++++- 9 files changed, 174 insertions(+), 32 deletions(-) create mode 100644 api/src/main/java/be/naaturel/boardmateapi/controllers/dtos/MoveDto.java create mode 100644 rpi/board_mate_client/models/move_dto.py diff --git a/api/src/main/java/be/naaturel/boardmateapi/controllers/GameController.java b/api/src/main/java/be/naaturel/boardmateapi/controllers/GameController.java index 63d2567a..2d56f7c4 100644 --- a/api/src/main/java/be/naaturel/boardmateapi/controllers/GameController.java +++ b/api/src/main/java/be/naaturel/boardmateapi/controllers/GameController.java @@ -2,6 +2,7 @@ package be.naaturel.boardmateapi.controllers; import be.naaturel.boardmateapi.common.exceptions.ServiceException; import be.naaturel.boardmateapi.common.models.Game; +import be.naaturel.boardmateapi.controllers.dtos.MoveDto; import be.naaturel.boardmateapi.controllers.dtos.ResponseBody; import be.naaturel.boardmateapi.controllers.dtos.GameDto; import be.naaturel.boardmateapi.controllers.mappings.GameMapper; @@ -60,10 +61,10 @@ public class GameController { } @PostMapping("/moves/add/{gameId}") - public ResponseEntity> AddMove(@PathVariable String gameId, @RequestBody String move){ + public ResponseEntity> AddMove(@PathVariable String gameId, @RequestBody MoveDto move){ ResponseBody result = ResponseBody.createEmpty(); try{ - String gamedId = service.addMove(gameId, move); + String gamedId = service.addMove(gameId, move.getNotation()); result.setSuccess(true); result.setData(gamedId); return ResponseEntity diff --git a/api/src/main/java/be/naaturel/boardmateapi/controllers/dtos/MoveDto.java b/api/src/main/java/be/naaturel/boardmateapi/controllers/dtos/MoveDto.java new file mode 100644 index 00000000..5c66fa51 --- /dev/null +++ b/api/src/main/java/be/naaturel/boardmateapi/controllers/dtos/MoveDto.java @@ -0,0 +1,13 @@ +package be.naaturel.boardmateapi.controllers.dtos; + +public class MoveDto { + private String notation; + + public String getNotation() { + return notation; + } + + public void setNotation(String notation){ + this.notation = notation; + } +} diff --git a/rpi/api-resources/board-mate.yaml b/rpi/api-resources/board-mate.yaml index b62bd998..f1fac6dc 100644 --- a/rpi/api-resources/board-mate.yaml +++ b/rpi/api-resources/board-mate.yaml @@ -6,7 +6,6 @@ info: servers: - url: "https://boardmate_api" paths: - /games/{id}: get: summary: "GET games/{id}" @@ -55,7 +54,7 @@ paths: content: application/json: schema: - type: "string" + $ref: "#/components/schemas/MoveDto" required: true responses: "200": @@ -109,4 +108,11 @@ components: increment: type: "integer" format: "int32" - nullable: true \ No newline at end of file + nullable: true + + MoveDto: + type: "object" + properties: + notation: + type: "string" + nullable: false \ No newline at end of file diff --git a/rpi/board_mate_client/__init__.py b/rpi/board_mate_client/__init__.py index 028ba8ce..734bcbdd 100644 --- a/rpi/board_mate_client/__init__.py +++ b/rpi/board_mate_client/__init__.py @@ -32,5 +32,6 @@ from board_mate_client.exceptions import ApiException # import models into sdk package from board_mate_client.models.game_dto import GameDto +from board_mate_client.models.move_dto import MoveDto from board_mate_client.models.response_body_game_dto import ResponseBodyGameDto from board_mate_client.models.response_body_string import ResponseBodyString diff --git a/rpi/board_mate_client/api/default_api.py b/rpi/board_mate_client/api/default_api.py index 6f5fa049..7676ad69 100644 --- a/rpi/board_mate_client/api/default_api.py +++ b/rpi/board_mate_client/api/default_api.py @@ -18,6 +18,7 @@ from typing_extensions import Annotated from pydantic import StrictStr from board_mate_client.models.game_dto import GameDto +from board_mate_client.models.move_dto import MoveDto from board_mate_client.models.response_body_game_dto import ResponseBodyGameDto from board_mate_client.models.response_body_string import ResponseBodyString @@ -43,7 +44,7 @@ class DefaultApi: def add_move( self, game_id: StrictStr, - body: StrictStr, + move_dto: MoveDto, _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -62,8 +63,8 @@ class DefaultApi: :param game_id: (required) :type game_id: str - :param body: (required) - :type body: str + :param move_dto: (required) + :type move_dto: MoveDto :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -88,7 +89,7 @@ class DefaultApi: _param = self._add_move_serialize( game_id=game_id, - body=body, + move_dto=move_dto, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -113,7 +114,7 @@ class DefaultApi: def add_move_with_http_info( self, game_id: StrictStr, - body: StrictStr, + move_dto: MoveDto, _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -132,8 +133,8 @@ class DefaultApi: :param game_id: (required) :type game_id: str - :param body: (required) - :type body: str + :param move_dto: (required) + :type move_dto: MoveDto :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -158,7 +159,7 @@ class DefaultApi: _param = self._add_move_serialize( game_id=game_id, - body=body, + move_dto=move_dto, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -183,7 +184,7 @@ class DefaultApi: def add_move_without_preload_content( self, game_id: StrictStr, - body: StrictStr, + move_dto: MoveDto, _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -202,8 +203,8 @@ class DefaultApi: :param game_id: (required) :type game_id: str - :param body: (required) - :type body: str + :param move_dto: (required) + :type move_dto: MoveDto :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -228,7 +229,7 @@ class DefaultApi: _param = self._add_move_serialize( game_id=game_id, - body=body, + move_dto=move_dto, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -248,7 +249,7 @@ class DefaultApi: def _add_move_serialize( self, game_id, - body, + move_dto, _request_auth, _content_type, _headers, @@ -274,8 +275,8 @@ class DefaultApi: # process the header parameters # process the form parameters # process the body parameter - if body is not None: - _body_params = body + if move_dto is not None: + _body_params = move_dto # set the HTTP header `Accept` diff --git a/rpi/board_mate_client/models/__init__.py b/rpi/board_mate_client/models/__init__.py index 4898614d..84ce4f7f 100644 --- a/rpi/board_mate_client/models/__init__.py +++ b/rpi/board_mate_client/models/__init__.py @@ -15,5 +15,6 @@ # import models into model package from board_mate_client.models.game_dto import GameDto +from board_mate_client.models.move_dto import MoveDto from board_mate_client.models.response_body_game_dto import ResponseBodyGameDto from board_mate_client.models.response_body_string import ResponseBodyString diff --git a/rpi/board_mate_client/models/move_dto.py b/rpi/board_mate_client/models/move_dto.py new file mode 100644 index 00000000..98184143 --- /dev/null +++ b/rpi/board_mate_client/models/move_dto.py @@ -0,0 +1,87 @@ +# coding: utf-8 + +""" + boardmate_api API + + boardmate_api API + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from typing import Optional, Set +from typing_extensions import Self + +class MoveDto(BaseModel): + """ + MoveDto + """ # noqa: E501 + notation: Optional[StrictStr] = None + __properties: ClassVar[List[str]] = ["notation"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of MoveDto from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([ + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of MoveDto from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "notation": obj.get("notation") + }) + return _obj + + diff --git a/rpi/controllers/board_mate_controller.py b/rpi/controllers/board_mate_controller.py index f7682bb2..9a878c42 100644 --- a/rpi/controllers/board_mate_controller.py +++ b/rpi/controllers/board_mate_controller.py @@ -1,4 +1,4 @@ -from board_mate_client import ApiClient, DefaultApi, GameDto +from board_mate_client import ApiClient, DefaultApi, GameDto, MoveDto class ApiController: @@ -10,14 +10,12 @@ class ApiController: try: with ApiClient(self.config) as client: api = DefaultApi(client) - game = GameDto( - white_name="Alice", - black_name="Bob", - time_value=300, - increment=10 + 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) @@ -29,4 +27,15 @@ class ApiController: with ApiClient(self.config) as client: api = DefaultApi(client) response = api.retrieve_games(game_id) - return GameDto.from_dict(response.data) \ No newline at end of file + 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) \ No newline at end of file diff --git a/rpi/main.py b/rpi/main.py index a7f2673c..802a49b3 100644 --- a/rpi/main.py +++ b/rpi/main.py @@ -10,7 +10,30 @@ if __name__ == "__main__": controller = ApiController(config) - game_id = controller.create_party("Aude Vaiselle", "Jean Porte", 30, 0) - print(game_id) - data = controller.retrieve_game(game_id) - print(data) \ No newline at end of file + controller.add_move("693f288327f9ffb33360fa45", "e4") + + white_name = input("White Name: ") + black_name = input("Black Name: ") + time_value = int(input("Time value: ")) + increment = int(input("Increment: ")) + print("Creating the party...") + + game_id = controller.create_party(white_name, black_name, time_value, increment) + if game_id is None : + print("An error occurred while creating the party. Exiting...") + exit() + + print("Party Created!") + + currentPlayer = 0 + while True: + message = None + if currentPlayer == 0 : + message = "White to play" + currentPlayer = 1 + else : + message = "Black to play" + currentPlayer = 0 + + move = input(f"{message} : ") +