summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-09-02 00:30:16 +0200
committerBotond Hende <nettingman@gmail.com>2024-09-02 00:30:16 +0200
commit5f67692c2424ce54c8dd754ef87d8d753759700e (patch)
treeeec7f1b3c626f2bbc4a971214e0d75eab70b6b84
parent1638f40eccc4a1321ee1bf19e3756157b6c965e1 (diff)
renamed/refactored code
-rw-r--r--__main__.py6
-rw-r--r--apirouters/auth.py (renamed from apirouters/agents.py)0
-rw-r--r--apirouters/customize_ship.py2
-rw-r--r--apirouters/tasks.py5
-rw-r--r--modules/ships.py4
5 files changed, 9 insertions, 8 deletions
diff --git a/__main__.py b/__main__.py
index 662d7f3..55fa740 100644
--- a/__main__.py
+++ b/__main__.py
@@ -2,7 +2,7 @@ from contextlib import asynccontextmanager
from fastapi import FastAPI
-from .apirouters import agents, tasks, customize_ship
+from .apirouters import auth, tasks, customize_ship
from .modules.database import cursor, conn
@@ -13,12 +13,12 @@ async def lifespan(application: FastAPI):
cursor.execute(
"CREATE TABLE IF NOT EXISTS ships(primary_key INTEGER PRIMARY KEY, symbol TEXT NOT NULL UNIQUE, task TEXT NOT NULL, params TEXT, name TEXT)")
conn.commit()
- agents.load_agents_from_database()
+ auth.load_agents_from_database()
yield
app = FastAPI(lifespan=lifespan)
-app.include_router(agents.router)
+app.include_router(auth.router)
app.include_router(tasks.router)
app.include_router(customize_ship.router)
diff --git a/apirouters/agents.py b/apirouters/auth.py
index 49d3740..49d3740 100644
--- a/apirouters/agents.py
+++ b/apirouters/auth.py
diff --git a/apirouters/customize_ship.py b/apirouters/customize_ship.py
index ca3ef83..5f0666e 100644
--- a/apirouters/customize_ship.py
+++ b/apirouters/customize_ship.py
@@ -13,7 +13,7 @@ class RenameBody(BaseModel):
@router.post("/customize_ship/{ship_symbol}/rename")
-async def rename(ship_symbol: str, rename_body: RenameBody, ship: Annotated[Ship, Depends(ships.get_ship)]):
+async def rename(rename_body: RenameBody, ship: Annotated[Ship, Depends(ships.get_ship)]):
ship.rename(rename_body.name)
return ship.get_data()
diff --git a/apirouters/tasks.py b/apirouters/tasks.py
index 684cf60..87fdb6e 100644
--- a/apirouters/tasks.py
+++ b/apirouters/tasks.py
@@ -2,16 +2,17 @@ from typing import Annotated
from fastapi import APIRouter, Depends
from pydantic import BaseModel
-from . import agents
+from . import auth
from ..modules import ships
from ..entities import task_types
from ..entities.ship import Ship
+from ..entities.agent import Agent
router = APIRouter()
@router.get("/tasks")
-async def get_tasks(agent: Annotated[agents.Agent, Depends(agents.auth_agent)]):
+async def get_tasks(agent: Annotated[Agent, Depends(auth.auth_agent)]):
ret_list = []
for current_ship in agent.ships.values():
ret_list.append(current_ship.get_data())
diff --git a/modules/ships.py b/modules/ships.py
index 9b0d4bd..4a6d0d6 100644
--- a/modules/ships.py
+++ b/modules/ships.py
@@ -2,12 +2,12 @@ from typing import Annotated
from fastapi import Depends, HTTPException
-from ..apirouters import agents
+from ..apirouters import auth
from ..entities.agent import Agent
from ..entities.ship import Ship
-async def get_ship(ship_symbol: str, agent: Annotated[Agent, Depends(agents.auth_agent)]) -> Ship:
+async def get_ship(ship_symbol: str, agent: Annotated[Agent, Depends(auth.auth_agent)]) -> Ship:
for ship in agent.ships.values():
if ship.symbol == ship_symbol:
return ship