List orders needing attention
Python · FastAPI · intermediate · greenfield
Adds the attention-list endpoint: filters orders down to the ones that need attention and returns them newest first. Matches the sample data.
Requirements
- Return orders that need attention: status is 'pending' OR 'failed'.
- Exclude orders that have been cancelled, even if they are pending or failed.
- Return them newest first.
Files touched
- app/routes/attention.py
--- app/routes/attention.py
+from fastapi import APIRouter
+from app.orders import all_orders
+
+router = APIRouter()
+
+
[email protected]("/orders/attention")
+async def orders_needing_attention():
+ orders = [
+ o
+ for o in all_orders()
+ if o.status in ("pending", "failed") and not o.cancelled
+ ]
+ return sorted(orders, key=lambda o: o.created_at)