artifacts-dashboard/backend/app/api/characters.py
Paweł Orzech f845647934
Some checks failed
Release / release (push) Has been cancelled
Initial release: Artifacts MMO Dashboard & Automation Platform
Full-stack dashboard for controlling, automating, and analyzing
Artifacts MMO characters via the game's HTTP API.

Backend (FastAPI):
- Async Artifacts API client with rate limiting and retry
- 6 automation strategies (combat, gathering, crafting, trading, task, leveling)
- Automation engine with runner, manager, cooldown tracker, pathfinder
- WebSocket relay (game server -> frontend)
- Game data cache, character snapshots, price history, analytics
- 9 API routers, 7 database tables, 3 Alembic migrations
- 108 unit tests

Frontend (Next.js 15 + shadcn/ui):
- Live character dashboard with HP/XP bars and cooldowns
- Character detail with stats, equipment, inventory, skills, manual actions
- Automation management with live log streaming
- Interactive canvas map with content-type coloring and zoom/pan
- Bank management, Grand Exchange with price charts
- Events, logs, analytics pages with Recharts
- WebSocket auto-reconnect with query cache invalidation
- Settings page, error boundaries, dark theme

Infrastructure:
- Docker Compose (dev + prod)
- GitHub Actions CI/CD
- Documentation (Architecture, Automation, Deployment, API)
2026-03-01 19:46:45 +01:00

46 lines
1.6 KiB
Python

from fastapi import APIRouter, HTTPException, Request
from httpx import HTTPStatusError
from app.schemas.game import CharacterSchema
from app.services.artifacts_client import ArtifactsClient
from app.services.character_service import CharacterService
router = APIRouter(prefix="/api/characters", tags=["characters"])
def _get_client(request: Request) -> ArtifactsClient:
return request.app.state.artifacts_client
def _get_service(request: Request) -> CharacterService:
return request.app.state.character_service
@router.get("/", response_model=list[CharacterSchema])
async def list_characters(request: Request) -> list[CharacterSchema]:
"""Return all characters belonging to the authenticated account."""
client = _get_client(request)
service = _get_service(request)
try:
return await service.get_all(client)
except HTTPStatusError as exc:
raise HTTPException(
status_code=exc.response.status_code,
detail=f"Artifacts API error: {exc.response.text}",
) from exc
@router.get("/{name}", response_model=CharacterSchema)
async def get_character(name: str, request: Request) -> CharacterSchema:
"""Return a single character by name."""
client = _get_client(request)
service = _get_service(request)
try:
return await service.get_one(client, name)
except HTTPStatusError as exc:
if exc.response.status_code == 404:
raise HTTPException(status_code=404, detail="Character not found") from exc
raise HTTPException(
status_code=exc.response.status_code,
detail=f"Artifacts API error: {exc.response.text}",
) from exc