From 1638f40eccc4a1321ee1bf19e3756157b6c965e1 Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Mon, 2 Sep 2024 00:21:13 +0200 Subject: refactored code, use get_ship dependency for ship related calls --- apirouters/customize_ship.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'apirouters/customize_ship.py') 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."} -- cgit v1.2.3-70-g09d2