From 6a8ef984cb492b8e09076a25b3cdde5bca67c41e Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Fri, 10 Apr 2026 15:37:05 +0200 Subject: [PATCH] fix: GET/POST /api/athlete work without a pre-existing athlete.json --- bincio/serve/server.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bincio/serve/server.py b/bincio/serve/server.py index 3b544c7..30bf920 100644 --- a/bincio/serve/server.py +++ b/bincio/serve/server.py @@ -449,9 +449,9 @@ 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 = json.loads(athlete_path.read_text(encoding="utf-8")) + 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" if edits_path.exists(): @@ -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)