from fastapi import APIRouter, Depends, HTTPException from app.core.security import admin_auth from app.repositories import device_repository from app.schemas.device import DeviceSetDisabledRequest router = APIRouter(tags=["admin-device"]) @router.get("/admin/device/list") def admin_device_list(app_id: str = "", auth=Depends(admin_auth)): return {"list": device_repository.list_devices(app_id)} @router.post("/admin/device/set-disabled") def admin_device_set_disabled(body: DeviceSetDisabledRequest, auth=Depends(admin_auth)): device_id = body.device_id.strip() disabled = bool(body.disabled) reason = body.reason.strip() updated = device_repository.set_device_disabled(device_id, disabled, reason) if updated != 1: raise HTTPException(status_code=404, detail="设备不存在") return {"msg": "设备已禁用" if disabled else "设备已恢复", "device_id": device_id}