fix: GET/POST /api/athlete work without a pre-existing athlete.json
This commit is contained in:
+10
-4
@@ -449,8 +449,8 @@ async def get_athlete(bincio_session: Optional[str] = Cookie(default=None)) -> J
|
|||||||
user = _require_user(bincio_session)
|
user = _require_user(bincio_session)
|
||||||
dd = _get_data_dir() / user.handle
|
dd = _get_data_dir() / user.handle
|
||||||
athlete_path = dd / "athlete.json"
|
athlete_path = dd / "athlete.json"
|
||||||
if not athlete_path.exists():
|
data: dict = {}
|
||||||
raise HTTPException(404, "athlete.json not found — run bincio extract first")
|
if athlete_path.exists():
|
||||||
data = json.loads(athlete_path.read_text(encoding="utf-8"))
|
data = json.loads(athlete_path.read_text(encoding="utf-8"))
|
||||||
# Layer edits/athlete.yaml on top
|
# Layer edits/athlete.yaml on top
|
||||||
edits_path = dd / "edits" / "athlete.yaml"
|
edits_path = dd / "edits" / "athlete.yaml"
|
||||||
@@ -480,8 +480,14 @@ async def save_athlete(
|
|||||||
) -> JSONResponse:
|
) -> JSONResponse:
|
||||||
user = _require_user(bincio_session)
|
user = _require_user(bincio_session)
|
||||||
dd = _get_data_dir() / user.handle
|
dd = _get_data_dir() / user.handle
|
||||||
if not (dd / "athlete.json").exists():
|
athlete_path = dd / "athlete.json"
|
||||||
raise HTTPException(404, "athlete.json not found — run bincio extract first")
|
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()
|
payload = await request.json()
|
||||||
edits_dir = dd / "edits"
|
edits_dir = dd / "edits"
|
||||||
edits_dir.mkdir(exist_ok=True)
|
edits_dir.mkdir(exist_ok=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user