summaryrefslogtreecommitdiff
path: root/modules/ships.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/ships.py')
-rw-r--r--modules/ships.py46
1 files changed, 10 insertions, 36 deletions
diff --git a/modules/ships.py b/modules/ships.py
index 05ce6c1..9b0d4bd 100644
--- a/modules/ships.py
+++ b/modules/ships.py
@@ -1,41 +1,15 @@
-from typing import Dict
+from typing import Annotated
-from . import task_types
-from .database import cursor, conn
+from fastapi import Depends, HTTPException
+from ..apirouters import agents
+from ..entities.agent import Agent
+from ..entities.ship import Ship
-class Ship:
- def __init__(self, symbol: str):
- self.symbol = symbol
- self.callsign = "-".split(symbol)[0]
- self.task = None
- self.name = None
+async def get_ship(ship_symbol: str, agent: Annotated[Agent, Depends(agents.auth_agent)]) -> Ship:
+ for ship in agent.ships.values():
+ if ship.symbol == ship_symbol:
+ return ship
- def get_data(self) -> Dict:
- return {"name": self.name, "symbol": self.symbol, "task": self.task}
-
- def load_task(self):
- cursor.execute("SELECT name, task, params FROM ships WHERE symbol = ?", (self.symbol,))
- row = cursor.fetchone()
- if row is None:
- cursor.execute("INSERT INTO ships (symbol, task, params, name) VALUES (?, ?, ?, ?)",
- (self.symbol, task_types.IDLE, None, self.symbol))
- conn.commit()
-
- self.task = task_types.IDLE
- self.task = self.symbol
- else:
- self.name = row[0]
- self.task = row[1]
-
- def set_task(self, task):
- self.task = task
- if task != task_types.ERROR:
- cursor.execute("UPDATE ships SET task = ? WHERE symbol = ?", (task, self.symbol))
- conn.commit()
-
- def rename(self, name):
- self.name = name
- cursor.execute("UPDATE ships SET name = ? WHERE symbol = ?", (name, self.symbol))
- conn.commit()
+ raise HTTPException(status_code=400, detail="Unknown ship symbol.")