first
This commit is contained in:
33
backend/app/routers/actions.py
Normal file
33
backend/app/routers/actions.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.services.entity_actions import disable_entity, enable_entity, set_flag
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class BulkActionRequest(BaseModel):
|
||||
action: str # disable, enable, favorite, unfavorite, ignore, unignore
|
||||
entity_ids: list[str]
|
||||
|
||||
|
||||
@router.post("/entities/actions")
|
||||
async def bulk_action(req: BulkActionRequest):
|
||||
results = []
|
||||
|
||||
if req.action in ("favorite", "unfavorite", "ignore", "unignore"):
|
||||
results = set_flag(req.entity_ids, req.action)
|
||||
elif req.action == "disable":
|
||||
for eid in req.entity_ids:
|
||||
r = await disable_entity(eid)
|
||||
results.append(r)
|
||||
elif req.action == "enable":
|
||||
for eid in req.entity_ids:
|
||||
r = await enable_entity(eid)
|
||||
results.append(r)
|
||||
else:
|
||||
return {"error": f"Action inconnue : {req.action}"}
|
||||
|
||||
return {"action": req.action, "results": results}
|
||||
Reference in New Issue
Block a user