summaryrefslogtreecommitdiff
path: root/apirouters/customize_ship.py
blob: c69d421c1edd1fcabc5f2b51045a897d9e83e5f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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


# TODO depend on ship instead of auth_agent
@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."}