blob: 5272f8dbc29223c709dc02c724bb11208d891fb3 (
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
35
|
from typing import Annotated
from fastapi import APIRouter, Depends
from pydantic import BaseModel
from . import auth
from ..modules import ships
from ..entities import task_types
from ..entities.ship import Ship
from ..entities.agent import Agent
router = APIRouter()
@router.get("/task")
async def get_tasks(agent: Annotated[Agent, Depends(auth.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()
|