Some checks failed
Build & Push Docker / build (push) Has been cancelled
- Remove all Excel code (import, export, template, pandas, openpyxl) - New canvas-based schedule editor with drag & drop (interact.js) - Modern 3-panel UI: sidebar, canvas, documentation tab - New data model: Block with id/date/start/end, ProgramType with id/name/color - Clean API: GET /api/health, POST /api/validate, GET /api/sample, POST /api/generate-pdf - Rewritten PDF generator using ScenarioDocument directly (no DataFrame) - Professional PDF output: dark header, colored blocks, merged cells, legend, footer - Sample JSON: "Zimní výjezd oddílu" with 11 blocks, 3 program types - 30 tests passing (API, core models, PDF generation) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""Scenario API endpoints: health, validate, sample."""
|
|
|
|
import json
|
|
import os
|
|
|
|
from fastapi import APIRouter
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from app.config import VERSION
|
|
from app.models.event import ScenarioDocument
|
|
from app.models.responses import HealthResponse, ValidationResponse
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health", response_model=HealthResponse)
|
|
async def health():
|
|
return HealthResponse(version=VERSION)
|
|
|
|
|
|
@router.post("/validate", response_model=ValidationResponse)
|
|
async def validate_scenario(doc: ScenarioDocument):
|
|
"""Validate a ScenarioDocument."""
|
|
errors = []
|
|
|
|
if not doc.blocks:
|
|
errors.append("No blocks defined")
|
|
|
|
if not doc.program_types:
|
|
errors.append("No program types defined")
|
|
|
|
type_ids = {pt.id for pt in doc.program_types}
|
|
for i, block in enumerate(doc.blocks):
|
|
if block.type_id not in type_ids:
|
|
errors.append(f"Block {i+1}: unknown type '{block.type_id}'")
|
|
if block.start >= block.end:
|
|
errors.append(f"Block {i+1}: start time must be before end time")
|
|
|
|
return ValidationResponse(valid=len(errors) == 0, errors=errors)
|
|
|
|
|
|
@router.get("/sample")
|
|
async def get_sample():
|
|
"""Return sample ScenarioDocument JSON."""
|
|
sample_path = os.path.join(os.path.dirname(__file__), "..", "static", "sample.json")
|
|
sample_path = os.path.abspath(sample_path)
|
|
|
|
with open(sample_path, "r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
|
|
return JSONResponse(
|
|
content=data,
|
|
headers={"Content-Disposition": "attachment; filename=sample.json"}
|
|
)
|