From a994b822a4231061153c6b27d8c5d7307b59f8b0 Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Sun, 1 Sep 2024 23:33:15 +0200 Subject: ship task setting from request body --- apirouters/tasks.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'apirouters/tasks.py') diff --git a/apirouters/tasks.py b/apirouters/tasks.py index 293ab52..6cc9a25 100644 --- a/apirouters/tasks.py +++ b/apirouters/tasks.py @@ -27,15 +27,15 @@ async def get_tasks(ship_symbol: str, agent: Annotated[Agent, Depends(auth_agent return {"error": "Unknown ship symbol."} -@router.post("/task/{ship_symbol}/set/{task_type}") -async def get_tasks(ship_symbol: str, task: str, agent: Annotated[Agent, Depends(auth_agent)]): - if task not in task_type.task_types: - return {"error": "Invalid task."} +class SetTaskBody(BaseModel): + task: task_types.task_type + +@router.post("/task/{ship_symbol}/set") +async def get_tasks(ship_symbol: str, set_task: SetTaskBody, agent: Annotated[Agent, Depends(auth_agent)]): for current_ship in agent.ships.values(): if current_ship.symbol == ship_symbol: - current_ship.set_task(task) + current_ship.set_task(set_task.task) return current_ship.get_data() return {"error": "Unknown ship symbol."} - -- cgit v1.2.3-70-g09d2