User Log and Persistent Faction Information
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
"""Faction data population and status management endpoints."""
|
||||
#Faction data population and status management endpoints.
|
||||
import json
|
||||
from pathlib import Path
|
||||
from fastapi import APIRouter
|
||||
|
||||
from models import FactionRequest
|
||||
from services.server_state import STATE
|
||||
from services.torn_api import populate_friendly, populate_enemy, start_friendly_status_loop, start_enemy_status_loop
|
||||
from services.torn_api import (
|
||||
populate_friendly,
|
||||
populate_enemy,
|
||||
start_friendly_status_loop,
|
||||
start_enemy_status_loop,
|
||||
stop_friendly_status_loop,
|
||||
stop_enemy_status_loop
|
||||
)
|
||||
from utils import load_json_list
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["factions"])
|
||||
@@ -73,3 +80,30 @@ async def api_enemy_status():
|
||||
return {}
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
@router.post("/stop_friendly_status")
|
||||
async def api_stop_friendly_status():
|
||||
await stop_friendly_status_loop()
|
||||
return {"status": "friendly status loop stopped"}
|
||||
|
||||
|
||||
@router.post("/stop_enemy_status")
|
||||
async def api_stop_enemy_status():
|
||||
await stop_enemy_status_loop()
|
||||
return {"status": "enemy status loop stopped"}
|
||||
|
||||
|
||||
@router.get("/dashboard_state")
|
||||
async def get_dashboard_state():
|
||||
"""Get current dashboard state for restoring UI on page load"""
|
||||
return {
|
||||
"friendly_faction_id": STATE.friendly_faction_id,
|
||||
"enemy_faction_id": STATE.enemy_faction_id,
|
||||
"friendly_members": [m.model_dump() for m in STATE.friendly.values()],
|
||||
"enemy_members": [m.model_dump() for m in STATE.enemy.values()],
|
||||
"friendly_status_interval": STATE.friendly_status_interval,
|
||||
"enemy_status_interval": STATE.enemy_status_interval,
|
||||
"friendly_status_running": STATE.friendly_status_running,
|
||||
"enemy_status_running": STATE.enemy_status_running
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user