app.services.game_service module

class app.services.game_service.GameService(game_repository, game_params_repository, task_repository, user_points_repository, strategy_service, strategy_definition_service=None, task_params_repository=None)[source]

Bases: BaseService

Service class for managing games.

Parameters:
game_repository

Repository instance for games.

Type:

GameRepository

game_params_repository

Repository instance for game parameters.

Type:

GameParamsRepository

task_repository

Repository instance for tasks.

Type:

TaskRepository

strategy_service

Service instance for strategies.

Type:

StrategyService

__init__(game_repository, game_params_repository, task_repository, user_points_repository, strategy_service, strategy_definition_service=None, task_params_repository=None)[source]
Initializes the GameService with the provided repositories and

services.

strategy_definition_service is optional so existing call sites and tests that don’t exercise custom: strategyIds keep working; when omitted, attempting to PATCH a game with a custom: id raises a clear error instead of silently accepting it.

task_params_repository is optional for the same backward-compat reason; it is only needed by duplicate_game() to deep-copy each task’s params. When omitted, duplication raises a clear error instead of silently dropping params.

Parameters:
Return type:

None

async get_by_gameId(gameId, *, api_key=None, oauth_user_id=None, is_admin=False, enforce_scope=False)[source]

Retrieves a game by its game ID.

Parameters:
  • gameId (UUID) – The game ID.

  • api_key (str)

  • oauth_user_id (str)

  • is_admin (bool)

  • enforce_scope (bool)

Returns:

BaseGameResult – The game details.

Return type:

BaseGameResult

async delete_game_by_id(gameId, *, api_key=None, oauth_user_id=None, is_admin=False, enforce_scope=False)[source]

Deletes a game by its game ID.

Parameters:
  • gameId (UUID) – The game ID.

  • api_key (str)

  • oauth_user_id (str)

  • is_admin (bool)

  • enforce_scope (bool)

Raises:

NotFoundError – If the game is not found.

Return type:

BaseGameResult | dict[str, str]

async get_all_games(schema, api_key=None, oauth_user_id=None, is_admin=False)[source]

Retrieves all games based on the provided schema.

Parameters:
  • schema – The schema for filtering the games.

  • api_key (str) – The API key.

  • is_admin (bool)

Returns:

list – A list of all games matching the schema.

Return type:

FindGameResult

async get_by_externalId(externalGameId)[source]

Retrieves a game by its external game ID.

Parameters:

externalGameId (str) – The external game ID.

Returns:

object – The game details.

Return type:

Any

async create(schema, api_key=None, oauth_user_id=None)[source]

Creates a new game using the provided schema.

Parameters:
  • schema (PostCreateGame) – The schema representing the game to be created.

  • api_key (str) – The API key.

  • oauth_user_id (str) – The OAuth user ID.

Returns:

GameCreated – The created game details.

Return type:

GameCreated

async duplicate_game(gameId, externalGameId, *, api_key=None, oauth_user_id=None, is_admin=False, enforce_scope=False)[source]

Deep-copy a game into a brand new one under externalGameId.

Copies the source game’s platform, strategy and params, then every task with its own strategy and params. The new game’s params are recreated via create() so all the creation guards (slug validation, externalGameId uniqueness, strategy existence) run against the copy exactly as they would for a fresh game. Tasks are recreated directly through the repositories - the duplicate just needs the rows, not the elaborate per-task response shaping.

Duplicated tasks start in the default open status: a copy is a fresh task, not a resumption of the original’s lifecycle.

Parameters:
  • gameId (UUID)

  • externalGameId (str)

  • api_key (str)

  • oauth_user_id (str)

  • is_admin (bool)

  • enforce_scope (bool)

Return type:

GameCreated

async patch_game_by_externalGameId(externalGameId, schema)[source]

Updates a game by its external game ID using the provided schema.

Parameters:
  • externalGameId (str) – The external game ID.

  • schema (PatchGame) – The schema representing the updated data.

Returns:

ResponsePatchGame – The updated game details.

Return type:

ResponsePatchGame

async patch_game_by_id(gameId, schema, *, api_key=None, oauth_user_id=None, is_admin=False, enforce_scope=False)[source]

Updates a game by its game ID using the provided schema.

Parameters:
  • gameId (UUID) – The game ID.

  • schema (PatchGame) – The schema representing the updated data.

  • api_key (str)

  • oauth_user_id (str)

  • is_admin (bool)

  • enforce_scope (bool)

Returns:

ResponsePatchGame – The updated game details.

Return type:

ResponsePatchGame

async get_strategy_by_externalGameId(externalGameId)[source]

Retrieves the strategy associated with a game by its external game ID.

Parameters:

externalGameId (str) – The external game ID.

Returns:

dict – The strategy details.

Return type:

dict[str, Any]

async get_strategy_by_gameId(gameId, *, api_key=None, oauth_user_id=None, is_admin=False, enforce_scope=False)[source]

Retrieves the strategy associated with a game by its game ID.

Parameters:
  • gameId (UUID) – The game ID.

  • api_key (str)

  • oauth_user_id (str)

  • is_admin (bool)

  • enforce_scope (bool)

Returns:

dict – The strategy details.

Return type:

dict[str, Any]

async get_tasks_by_gameId(gameId, *, api_key=None, oauth_user_id=None, is_admin=False, enforce_scope=False)[source]

Retrieves the tasks associated with a game by its game ID.

Parameters:
  • gameId (UUID) – The game ID.

  • api_key (str)

  • oauth_user_id (str)

  • is_admin (bool)

  • enforce_scope (bool)

Returns:

dict – The game details including tasks.

Return type:

dict[str, Any]

async get_game_by_external_id(externalGameId, api_key=None, oauth_user_id=None)[source]

Retrieves a game by its external game ID.

Parameters:
  • externalGameId (str) – The external game ID.

  • api_key (str) – The API key.

  • oauth_user_id (str) – The OAuth user ID.

Returns:

dict – The game details.

Return type:

Any