app.repository.task_repository module¶
- class app.repository.task_repository.TaskRepository(session_factory, model=<class 'app.model.tasks.Tasks'>, model_task_params=<class 'app.model.task_params.TasksParams'>, model_user_points=<class 'app.model.user_points.UserPoints'>)[source]¶
Bases:
BaseRepositoryRepository class for tasks.
- Parameters:
session_factory (Callable[[...], AbstractAsyncContextManager[AsyncSession]])
- async read_by_gameId(schema, eager=False)[source]¶
Reads tasks filtered by gameId (and any other schema fields).
- Parameters:
eager (bool)
- async read_by_gameId_and_externalTaskId(gameId, externalTaskId)[source]¶
Look up a task by its game and external identifier.
- Parameters:
gameId – Internal identifier of the owning game.
externalTaskId (str) – External identifier of the task.
- Returns:
Tasks | None – The matching task, or
Noneif not found.
- async get_points_and_users_by_taskId(taskId)[source]¶
Fetch a task by its internal id, raising if it does not exist.
- Parameters:
taskId – Internal task identifier.
- Returns:
Tasks – The matching task.
- Raises:
NotFoundError – If no task has the given id.
- async patch_by_id(taskId, fields)[source]¶
Apply a small
fieldsdict to the task identified bytaskId. Returns the refreshed row. Used by thePATCH /games/{gameId}/tasks/{taskId}flow so the assignments admin view can rewritestrategyId(andstatus) without a full upsert.Raises
NotFoundErrorif the task does not exist.- Parameters:
fields (dict)
- async delete_task_by_id(task_id)[source]¶
Delete a single task and everything that hangs off it.
Mirrors the per-task branch of
GameRepository.delete_game_by_id(): task params and the user-points rows that reference the task are removed first so the FK constraints don’t block the finalDELETEon the task row. ReturnsTrueon success.Raises
NotFoundErrorif the task does not exist.
- async list_by_strategy_id(strategy_id)[source]¶
Return all tasks whose
strategyIdmatches the given value.Rollback cascade companion to
GameRepository.list_by_strategy_id().- Parameters:
strategy_id (str)
- async bulk_update_strategy_id(*, old_strategy_id, new_strategy_id)[source]¶
Rewrite every task’s
strategyIdfromold_strategy_idtonew_strategy_idin a single UPDATE. Returns the row count.Rollback cascade companion to
GameRepository.bulk_update_strategy_id().- Parameters:
old_strategy_id (str)
new_strategy_id (str)
- Return type:
int