fix: GET/POST /api/athlete work without a pre-existing athlete.json
This commit is contained in:
+11
-5
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user