diff options
author | Botond Hende <nettingman@gmail.com> | 2024-09-01 00:58:59 +0200 |
---|---|---|
committer | Botond Hende <nettingman@gmail.com> | 2024-09-01 00:58:59 +0200 |
commit | f55028d8d7d703f348190598d2fce93103070d17 (patch) | |
tree | 68fd302176de71220b63e38462871d99668a20a5 /apirouters | |
parent | e66fb136c8fd10fe8bafb273c938a3d332d997ba (diff) |
ship customization: renaming
Diffstat (limited to 'apirouters')
-rw-r--r-- | apirouters/customize_ship.py | 21 | ||||
-rw-r--r-- | apirouters/tasks.py | 13 |
2 files changed, 27 insertions, 7 deletions
diff --git a/apirouters/customize_ship.py b/apirouters/customize_ship.py new file mode 100644 index 0000000..7be3279 --- /dev/null +++ b/apirouters/customize_ship.py @@ -0,0 +1,21 @@ +from typing import Annotated +from fastapi import APIRouter, Depends +from pydantic import BaseModel + +from .agents import auth_agent, Agent + +router = APIRouter() + + +class RenameBody(BaseModel): + name: str + + +@router.post("/customize_ship/{ship_symbol}/rename") +async def rename(ship_symbol: str, rename_body: RenameBody, agent: Annotated[Agent, Depends(auth_agent)]): + for current_ship in agent.ships.values(): + if current_ship.symbol == ship_symbol: + current_ship.rename(rename_body.name) + return current_ship.get_data() + + return {"error": "Unknown ship symbol."} diff --git a/apirouters/tasks.py b/apirouters/tasks.py index 806de91..293ab52 100644 --- a/apirouters/tasks.py +++ b/apirouters/tasks.py @@ -1,8 +1,6 @@ from typing import Annotated from fastapi import APIRouter, Depends -from ..modules.database import cursor, conn -from ..modules.ships import Ship from ..modules import task_type from .agents import auth_agent, Agent @@ -12,9 +10,9 @@ router = APIRouter() @router.get("/tasks") async def get_tasks(agent: Annotated[Agent, Depends(auth_agent)]): ships = [] - for ship in agent.ships.values(): - ship.load_task() - ships.append({"symbol": ship.symbol, "task": ship.task}) + for current_ship in agent.ships.values(): + current_ship.load_task() + ships.append(current_ship.get_data()) return {"ships": ships} @@ -24,7 +22,7 @@ async def get_tasks(ship_symbol: str, agent: Annotated[Agent, Depends(auth_agent for current_ship in agent.ships.values(): if current_ship.symbol == ship_symbol: current_ship.load_task() - return {"symbol": current_ship.symbol, "task": current_ship.task} + return current_ship.get_data() return {"error": "Unknown ship symbol."} @@ -37,6 +35,7 @@ async def get_tasks(ship_symbol: str, task: str, agent: Annotated[Agent, Depends for current_ship in agent.ships.values(): if current_ship.symbol == ship_symbol: current_ship.set_task(task) - return {"symbol": current_ship.symbol, "task": current_ship.task} + return current_ship.get_data() return {"error": "Unknown ship symbol."} + |