summaryrefslogtreecommitdiff
path: root/apirouters/customize_ship.py
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-09-02 00:21:13 +0200
committerBotond Hende <nettingman@gmail.com>2024-09-02 00:21:13 +0200
commit1638f40eccc4a1321ee1bf19e3756157b6c965e1 (patch)
tree99209de68ebcd4f42cafcdf14e563d7916d69e00 /apirouters/customize_ship.py
parent3a390ff218903b8665a99f94d7f3a65357b6e96d (diff)
refactored code, use get_ship dependency for ship related calls
Diffstat (limited to 'apirouters/customize_ship.py')
-rw-r--r--apirouters/customize_ship.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/apirouters/customize_ship.py b/apirouters/customize_ship.py
index c69d421..ca3ef83 100644
--- a/apirouters/customize_ship.py
+++ b/apirouters/customize_ship.py
@@ -2,7 +2,8 @@ from typing import Annotated
from fastapi import APIRouter, Depends
from pydantic import BaseModel
-from .agents import auth_agent, Agent
+from ..modules import ships
+from ..entities.ship import Ship
router = APIRouter()
@@ -11,12 +12,8 @@ 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()
+async def rename(ship_symbol: str, rename_body: RenameBody, ship: Annotated[Ship, Depends(ships.get_ship)]):
+ ship.rename(rename_body.name)
+ return ship.get_data()
- return {"error": "Unknown ship symbol."}