new changes
This commit is contained in:
@@ -72,6 +72,38 @@ async def site_create(
|
||||
return result
|
||||
|
||||
|
||||
class SiteBatchRequest(BaseModel):
|
||||
action: str
|
||||
ids: list[int]
|
||||
|
||||
|
||||
@router.post("/batch")
|
||||
async def site_batch(
|
||||
body: SiteBatchRequest,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Bulk enable, disable, or delete sites by id."""
|
||||
if body.action not in ("enable", "disable", "delete"):
|
||||
raise HTTPException(status_code=400, detail="action must be enable, disable, or delete")
|
||||
if not body.ids:
|
||||
raise HTTPException(status_code=400, detail="ids required")
|
||||
results: list[dict] = []
|
||||
for sid in body.ids:
|
||||
if body.action == "delete":
|
||||
r = await delete_site(db, sid)
|
||||
elif body.action == "enable":
|
||||
r = await set_site_status(db, sid, 1)
|
||||
else:
|
||||
r = await set_site_status(db, sid, 0)
|
||||
results.append({
|
||||
"id": sid,
|
||||
"ok": bool(r.get("status")),
|
||||
"msg": r.get("msg", ""),
|
||||
})
|
||||
return {"results": results}
|
||||
|
||||
|
||||
@router.get("/{site_id}")
|
||||
async def site_get(
|
||||
site_id: int,
|
||||
|
||||
Reference in New Issue
Block a user