fix: GET/POST /api/athlete work without a pre-existing athlete.json

This commit is contained in:
Davide Scaini
2026-04-10 15:37:05 +02:00
parent f790deb54f
commit 6a8ef984cb
+10 -4
View File
@@ -449,8 +449,8 @@ async def get_athlete(bincio_session: Optional[str] = Cookie(default=None)) -> J
user = _require_user(bincio_session)
dd = _get_data_dir() / user.handle
athlete_path = dd / "athlete.json"
if not athlete_path.exists():
raise HTTPException(404, "athlete.json not found — run bincio extract first")
data: dict = {}
if athlete_path.exists():
data = json.loads(athlete_path.read_text(encoding="utf-8"))
# Layer edits/athlete.yaml on top
edits_path = dd / "edits" / "athlete.yaml"
@@ -480,8 +480,14 @@ async def save_athlete(
) -> JSONResponse:
user = _require_user(bincio_session)
dd = _get_data_dir() / user.handle
if not (dd / "athlete.json").exists():
raise HTTPException(404, "athlete.json not found — run bincio extract first")
athlete_path = dd / "athlete.json"
if not athlete_path.exists():
from datetime import datetime, timezone
athlete_path.write_text(json.dumps({
"bas_version": "1.0",
"generated_at": datetime.now(timezone.utc).isoformat(),
"power_curve": {},
}), encoding="utf-8")
payload = await request.json()
edits_dir = dd / "edits"
edits_dir.mkdir(exist_ok=True)