Fix move quoting

This commit is contained in:
2025-12-14 23:13:39 +01:00
parent 9ee3539eeb
commit 499639823e
9 changed files with 174 additions and 32 deletions

View File

@@ -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<ResponseBody<String>> AddMove(@PathVariable String gameId, @RequestBody String move){
public ResponseEntity<ResponseBody<String>> AddMove(@PathVariable String gameId, @RequestBody MoveDto move){
ResponseBody<String> 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

View File

@@ -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;
}
}

View File

@@ -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
nullable: true
MoveDto:
type: "object"
properties:
notation:
type: "string"
nullable: false

View File

@@ -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

View File

@@ -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`

View File

@@ -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

View File

@@ -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

View File

@@ -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)
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)

View File

@@ -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)
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} : ")