diff --git a/packetserver/http/routers/objects.py b/packetserver/http/routers/objects.py index 117c737..a79dd9a 100644 --- a/packetserver/http/routers/objects.py +++ b/packetserver/http/routers/objects.py @@ -346,4 +346,38 @@ async def update_object( private=obj.private, created_at=obj.created_at, modified_at=obj.modified_at - ) \ No newline at end of file + ) + +@router.delete("/objects/{uuid}", status_code=204) +async def delete_object( + uuid: UUID, + db: DbDependency, + current_user: HttpUser = Depends(get_current_http_user) +): + username = current_user.username + + try: + with db.transaction() as conn: + root = conn.root() + + obj = Object.get_object_by_uuid(uuid, root) + if not obj: + raise HTTPException(status_code=404, detail="Object not found") + + user = User.get_user_by_username(username, root) + if not user or user.uuid != obj.owner: + raise HTTPException(status_code=403, detail="Not authorized to delete this object") + + # Remove references + user.remove_obj_uuid(uuid) # from user's object_uuids set + del conn.root.objects[uuid] # from global objects mapping + + logging.info(f"User {username} deleted object {uuid}") + + except HTTPException: + raise + except Exception as e: + logging.error(f"Object delete failed for {username} on {uuid}: {e}\n{traceback.format_exc()}") + raise HTTPException(status_code=500, detail="Failed to delete object") + + return None \ No newline at end of file