feat: add weight fields to athlete profile and gear items
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user