Fix: /breeder/my-editor Endpoint (Crash 'Cannot destructure profile') + Läufigkeit in Züchter-Bereich

breeder-editor.js (aus 459cd42) rief /api/breeder/my-editor auf — Endpoint
existierte nie (gleicher Worktree-Verlust wie /partner/my-profile). Jetzt
gebaut: profile + litters + storage_mb/limit; ohne Profil klare 404 statt
Destrukturierungs-Crash. 3 Tests.

Läufigkeit (Rene): eigener HUND-Chip entfällt, stattdessen vierte Karte im
Züchter-Bereich (Zyklen, Progesterontests, Deckdaten). Suite: 58 passed.
This commit is contained in:
rene 2026-06-07 20:04:43 +02:00
parent ed7c469c6a
commit 487dacc7c7
9 changed files with 100 additions and 20 deletions

View file

@ -491,6 +491,43 @@ class BreederProfileUpdate(BaseModel):
website: Optional[str] = Field(None, max_length=500)
beschreibung: Optional[str] = Field(None, max_length=10000)
@router.get("/breeder/my-editor")
async def breeder_my_editor(user=Depends(require_breeder)):
"""Daten für den Profil-Editor: Profil + eigene Würfe + Speicherverbrauch.
(Frontend breeder-editor.js stammt aus 459cd42 dieser Lese-Endpoint
ging damals im Worktree-Merge verloren, wie /partner/my-profile.)"""
with db() as conn:
profile = conn.execute(
"SELECT * FROM breeder_profiles WHERE user_id=?", (user["id"],)
).fetchone()
if not profile:
raise HTTPException(404, "Noch kein Züchter-Profil angelegt.")
profile = dict(profile)
litters = [dict(r) for r in conn.execute(
"SELECT * FROM litters WHERE breeder_id=? ORDER BY created_at DESC",
(profile["id"],)
).fetchall()]
# Speicherverbrauch der Züchter-Medien (MEDIA_DIR/breeders/{breeder_id}/**)
media_dir = os.getenv("MEDIA_DIR", "/data/media")
base = os.path.join(media_dir, "breeders", str(profile["id"]))
total = 0
if os.path.isdir(base):
for root, _dirs, files in os.walk(base):
for f in files:
try:
total += os.path.getsize(os.path.join(root, f))
except OSError:
pass
return {
"profile": profile,
"litters": litters,
"storage_mb": round(total / (1024 * 1024), 4),
"storage_limit_mb": 200,
}
@router.put("/breeder/profile")
async def update_breeder_profile(body: BreederProfileUpdate, user=Depends(require_breeder)):
with db() as conn: