diff --git a/app/api/v1/endpoints/games.py b/app/api/v1/endpoints/games.py index 9aeef89f..8b72972b 100644 --- a/app/api/v1/endpoints/games.py +++ b/app/api/v1/endpoints/games.py @@ -16,53 +16,53 @@ ) -summary_get_games_list = "Get Games List" -description_get_games_list = """ -## Find Game -### Find all games and params -""" - - -@router.get( - "", - response_model=FindGameResult, - description=description_get_games_list, - summary=summary_get_games_list, -) -@inject -def get_games_list( - schema: PostFindGame = Depends(), - service: GameService = Depends(Provide[Container.game_service]), -): - return service.get_all_games(schema) - - -summary_get_game_by_id = "Get Game by Id" -description_get_game_by_id = """ -## Get Game by Id -### Get game by id -""" - - -@router.get( - "/{id}", - response_model=FindGameById, - description=description_get_game_by_id, - summary=summary_get_game_by_id, -) -@inject -def get_game_by_id( - id: UUID, - service: GameService = Depends(Provide[Container.game_service]), -): - - response = service.get_by_id(id) - return response +# summary_get_games_list = "Get Games List" +# description_get_games_list = """ +# ## Find Game +# ### Find all games and params +# """ + + +# @router.get( +# "", +# response_model=FindGameResult, +# description=description_get_games_list, +# summary=summary_get_games_list, +# ) +# @inject +# def get_games_list( +# schema: PostFindGame = Depends(), +# service: GameService = Depends(Provide[Container.game_service]), +# ): +# return service.get_all_games(schema) + + +# summary_get_game_by_id = "Get Game by Id" +# description_get_game_by_id = """ +# ## Get Game by Id +# ### Get game by id +# """ + + +# @router.get( +# "/{id}", +# response_model=FindGameById, +# description=description_get_game_by_id, +# summary=summary_get_game_by_id, +# ) +# @inject +# def get_game_by_id( +# id: UUID, +# service: GameService = Depends(Provide[Container.game_service]), +# ): + +# response = service.get_by_id(id) +# return response summary_create_game = "Create Game" description_create_game = """ -## Create Game +Create Game """ @@ -79,41 +79,54 @@ def create_game( ): return service.create(schema) - -summary_patch_game = "Update Game" -description_patch_game = """ -## Update Game -can update even the GameParams -""" - - -@router.patch("/{id}", response_model=ResponsePatchGame) -@inject -def patch_game( - id: str, - schema: PatchGame, - service: GameService = Depends(Provide[Container.game_service]), -): - return service.patch_game_by_id(id, schema) - - -summary_get_task_by_id_game = "Get Task by Id Game" -description_get_task_by_id_game = """ -## Get Task by Id Game -""" - - -@router.get( - "/{id}/tasks", - response_model=FindTaskGameById, - description=description_get_task_by_id_game, - summary=summary_get_task_by_id_game, -) -@inject -def get_task_by_id_game( - id: UUID, - service: GameService = Depends(Provide[Container.game_service]), -): - - response = service.get_tasks_by_gameId(id) - return response +# @router.post( +# "", +# response_model=GameCreated, +# summary=summary_create_game, +# description=description_create_game, +# ) +# @inject +# def create_game( +# schema: PostCreateGame, +# service: GameService = Depends(Provide[Container.game_service]), +# ): +# return service.create(schema) + + +# summary_patch_game = "Update Game" +# description_patch_game = """ +# Update Game +# can update even the GameParams +# """ + + +# @router.patch("/{id}", response_model=ResponsePatchGame) +# @inject +# def patch_game( +# id: str, +# schema: PatchGame, +# service: GameService = Depends(Provide[Container.game_service]), +# ): +# return service.patch_game_by_id(id, schema) + + +# summary_get_task_by_id_game = "Get Task by Id Game" +# description_get_task_by_id_game = """ +# Get Task by Id Game +# """ + + +# @router.get( +# "/{id}/tasks", +# response_model=FindTaskGameById, +# description=description_get_task_by_id_game, +# summary=summary_get_task_by_id_game, +# ) +# @inject +# def get_task_by_id_game( +# id: UUID, +# service: GameService = Depends(Provide[Container.game_service]), +# ): + +# response = service.get_tasks_by_gameId(id) +# return response diff --git a/app/schema/games_schema.py b/app/schema/games_schema.py index 573acb76..b4590106 100644 --- a/app/schema/games_schema.py +++ b/app/schema/games_schema.py @@ -22,6 +22,7 @@ class BaseGameResult(BaseModel): id: Optional[UUID] = None created_at: Optional[datetime] = None updated_at: Optional[datetime] = None + strategyId: Optional[str] = None externalGameId: Optional[str] = None platform: Optional[str] = None endDateTime: Optional[datetime] = None @@ -34,6 +35,7 @@ class Config: class PostCreateGame(BaseModel): externalGameId: str platform: str + strategyId: Optional[str] = "default" endDateTime: Optional[datetime] params: Optional[List[CreateGameParams]] @@ -79,17 +81,20 @@ class FindTaskGameById(ModelBaseInfo): tasks: Optional[List[Task]] -class Game(ModelBaseInfo, BaseGame, metaclass=AllOptional): ... +class Game(ModelBaseInfo, BaseGame, metaclass=AllOptional): + ... -class PostFindGame(FindBase, BaseGame, metaclass=AllOptional): ... +class PostFindGame(FindBase, BaseGame, metaclass=AllOptional): + ... class FindGameByExternalId(FindBase, BaseGame, metaclass=AllOptional): externalGameId: str -class UpsertGame(BaseGame, metaclass=AllOptional): ... +class UpsertGame(BaseGame, metaclass=AllOptional): + ... class UpsertGameWithGameParams(BaseGame, metaclass=AllOptional): diff --git a/app/services/game_service.py b/app/services/game_service.py index 41c15507..346b0899 100644 --- a/app/services/game_service.py +++ b/app/services/game_service.py @@ -30,7 +30,8 @@ def get_all_games(self, schema): return self.game_repository.get_all_games(schema) def get_by_externalId(self, externalGameId: str): - return self.game_repository.read_by_column("externalGameId", externalGameId) + return self.game_repository.read_by_column( + "externalGameId", externalGameId) def create(self, schema: PostCreateGame): params = schema.params @@ -41,7 +42,9 @@ def create(self, schema: PostCreateGame): ) if externalGameId_exist: raise ConflictError( - detail=(f"Game already exist with externalGameId: {externalGameId}") + detail=( + f"Game already exist with externalGameId: " + f"{externalGameId}") ) created_params = [] game = self.game_repository.create(schema) @@ -55,12 +58,15 @@ def create(self, schema: PostCreateGame): params_dict["gameId"] = str(game.id) params_to_insert = InsertGameParams(**params_dict) - created_param = self.game_params_repository.create(params_to_insert) + created_param = self.game_params_repository.create( + params_to_insert) created_params.append(created_param) response = GameCreated( - **game.dict(), params=created_params, message="Successfully created" + **game.dict(), params=created_params, + message=f"Game with externalGameId: {externalGameId} created" + f" successfully" ) return response @@ -72,14 +78,16 @@ def patch_game_by_id(self, id: UUID, schema: PatchGame): updated_params = [] if params: for param in params: - self.game_params_repository.patch_game_params_by_id(param.id, param) + self.game_params_repository.patch_game_params_by_id( + param.id, param) updated_params.append(param) updated_game_dict = updated_game.dict() updated_game_dict.pop("params", None) response = ResponsePatchGame( - **updated_game_dict, params=updated_params, message="Successfully updated" + **updated_game_dict, params=updated_params, + message="Successfully updated" ) return response