diff options
author | Botond Hende <nettingman@gmail.com> | 2024-09-01 23:33:15 +0200 |
---|---|---|
committer | Botond Hende <nettingman@gmail.com> | 2024-09-01 23:33:15 +0200 |
commit | a994b822a4231061153c6b27d8c5d7307b59f8b0 (patch) | |
tree | 0807c64b101c4f62d3795467e9da552536e5df87 /apirouters | |
parent | f55028d8d7d703f348190598d2fce93103070d17 (diff) |
ship task setting from request body
Diffstat (limited to 'apirouters')
-rw-r--r-- | apirouters/agents.py | 6 | ||||
-rw-r--r-- | apirouters/tasks.py | 12 |
2 files changed, 9 insertions, 9 deletions
diff --git a/apirouters/agents.py b/apirouters/agents.py index a1e015b..1b927e7 100644 --- a/apirouters/agents.py +++ b/apirouters/agents.py @@ -5,7 +5,7 @@ import openapi_client from fastapi import APIRouter, Depends, Response, HTTPException from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm -from ..modules import task_type +from ..modules import task_types from ..modules.database import cursor, conn from ..modules.ships import Ship @@ -87,7 +87,7 @@ def load_agents_from_database() -> None: ship.load_task() except: for ship in agent.ships.values(): - ship.set_task(tasks.ERROR) + ship.set_task(task_types.ERROR) cursor.execute("SELECT symbol FROM ships WHERE symbol LIKE ?", (f"{agent.agent_symbol}-%",)) ship_names = agent.ships.keys() @@ -96,7 +96,7 @@ def load_agents_from_database() -> None: continue missing_ship = Ship(row[0]) - missing_ship.set_task(tasks.MIA) + missing_ship.set_task(task_types.MIA) agent.ships[row[0]] = missing_ship 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."} - |