From f55028d8d7d703f348190598d2fce93103070d17 Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Sun, 1 Sep 2024 00:58:59 +0200 Subject: ship customization: renaming --- apirouters/customize_ship.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 apirouters/customize_ship.py (limited to 'apirouters/customize_ship.py') 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."} -- cgit v1.2.3-70-g09d2