Feature: Foto-Editor im Hundeprofil — Zoom, Drag-to-pan, Löschen
This commit is contained in:
parent
cb8ac8cffd
commit
913cebcba1
6 changed files with 234 additions and 35 deletions
|
|
@ -155,6 +155,43 @@ async def upload_photo(
|
|||
return {"foto_url": foto_url}
|
||||
|
||||
|
||||
class PhotoPosition(BaseModel):
|
||||
zoom: float = 1.0
|
||||
offset_x: float = 0.0
|
||||
offset_y: float = 0.0
|
||||
|
||||
|
||||
@router.patch("/{dog_id}/photo-position")
|
||||
async def update_photo_position(dog_id: int, pos: PhotoPosition, user=Depends(get_current_user)):
|
||||
with db() as conn:
|
||||
updated = conn.execute(
|
||||
"UPDATE dogs SET foto_zoom=?, foto_offset_x=?, foto_offset_y=? WHERE id=? AND user_id=?",
|
||||
(pos.zoom, pos.offset_x, pos.offset_y, dog_id, user["id"])
|
||||
).rowcount
|
||||
if not updated:
|
||||
raise HTTPException(404, "Hund nicht gefunden.")
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.delete("/{dog_id}/photo", status_code=204)
|
||||
async def delete_photo(dog_id: int, user=Depends(get_current_user)):
|
||||
with db() as conn:
|
||||
row = conn.execute(
|
||||
"SELECT foto_url FROM dogs WHERE id=? AND user_id=?", (dog_id, user["id"])
|
||||
).fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, "Hund nicht gefunden.")
|
||||
if row["foto_url"]:
|
||||
path = os.path.join(MEDIA_DIR, row["foto_url"].lstrip("/media/"))
|
||||
if os.path.exists(path):
|
||||
os.remove(path)
|
||||
with db() as conn:
|
||||
conn.execute(
|
||||
"UPDATE dogs SET foto_url=NULL, foto_zoom=1.0, foto_offset_x=0.0, foto_offset_y=0.0 WHERE id=?",
|
||||
(dog_id,)
|
||||
)
|
||||
|
||||
|
||||
# Öffentliches Profil (für NFC-Tag, kein Login nötig)
|
||||
@router.get("/public/{dog_id}")
|
||||
async def public_dog_profile(dog_id: int):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue