from typing import Annotated from fastapi import APIRouter, Depends from pydantic import BaseModel from . import agents from ..modules import ships from ..entities import task_types from ..entities.ship import Ship router = APIRouter() @router.get("/tasks") async def get_tasks(agent: Annotated[agents.Agent, Depends(agents.auth_agent)]): ret_list = [] for current_ship in agent.ships.values(): ret_list.append(current_ship.get_data()) return {"ships": ret_list} @router.get("/task/{ship_symbol}") async def get_tasks(ship: Annotated[Ship, Depends(ships.get_ship)]): return ship.get_data() class SetTaskBody(BaseModel): task: task_types.task_type @router.post("/task/{ship_symbol}/set") async def get_tasks(set_task: SetTaskBody, ship: Annotated[Ship, Depends(ships.get_ship)]): ship.set_task(set_task.task) return ship.get_data()