blob: 684cf60677762b78a5549b4966677fe3c8e4a605 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
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()
|