feat: add weight fields to athlete profile and gear items

This commit is contained in:
Davide Scaini
2026-06-03 23:39:03 +02:00
parent 060bdf5114
commit da351cc53b
4 changed files with 59 additions and 7 deletions
+22
View File
@@ -58,6 +58,14 @@ async def gear_add(
if gear_type not in _GEAR_TYPES:
raise HTTPException(400, f"type must be one of: {', '.join(sorted(_GEAR_TYPES))}")
strava_id = str(body.get("strava_id", "")).strip() or None
weight_g = body.get("weight_g")
if weight_g is not None:
try:
weight_g = int(weight_g)
if weight_g < 0:
raise ValueError
except (TypeError, ValueError):
raise HTTPException(400, "weight_g must be a non-negative integer (grams)")
user_dir = deps._get_data_dir() / user.handle
items = _load(user_dir)
@@ -75,6 +83,8 @@ async def gear_add(
}
if strava_id:
item["strava_id"] = strava_id
if weight_g is not None:
item["weight_g"] = weight_g
items.append(item)
_save(user_dir, items)
@@ -110,6 +120,18 @@ async def gear_update(
item["type"] = gear_type
if "retired" in body:
item["retired"] = bool(body["retired"])
if "weight_g" in body:
w = body["weight_g"]
if w is None:
item.pop("weight_g", None)
else:
try:
w = int(w)
if w < 0:
raise ValueError
except (TypeError, ValueError):
raise HTTPException(400, "weight_g must be a non-negative integer (grams)")
item["weight_g"] = w
items[idx] = item
_save(user_dir, items)