Move 3 Strikes from Admin to Dashboard, add strikes feature
- Adds strikes (0-3) to Child model with migration
- New PATCH /api/children/{id}/strikes endpoint with WebSocket broadcast
- TV dashboard shows red ✕ marks next to child name when strikes > 0
- 3 Strikes card on Dashboard page (removed from Admin)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from pydantic import BaseModel, Field
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
|
||||
@@ -6,6 +7,7 @@ from app.dependencies import get_db, get_current_user
|
||||
from app.models.child import Child
|
||||
from app.models.user import User
|
||||
from app.schemas.child import ChildCreate, ChildOut, ChildUpdate
|
||||
from app.websocket.manager import manager
|
||||
|
||||
router = APIRouter(prefix="/api/children", tags=["children"])
|
||||
|
||||
@@ -70,6 +72,30 @@ async def update_child(
|
||||
return child
|
||||
|
||||
|
||||
class StrikesBody(BaseModel):
|
||||
strikes: int = Field(..., ge=0, le=3)
|
||||
|
||||
|
||||
@router.patch("/{child_id}/strikes", response_model=ChildOut)
|
||||
async def update_strikes(
|
||||
child_id: int,
|
||||
body: StrikesBody,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
result = await db.execute(
|
||||
select(Child).where(Child.id == child_id, Child.user_id == current_user.id)
|
||||
)
|
||||
child = result.scalar_one_or_none()
|
||||
if not child:
|
||||
raise HTTPException(status_code=404, detail="Child not found")
|
||||
child.strikes = body.strikes
|
||||
await db.commit()
|
||||
await db.refresh(child)
|
||||
await manager.broadcast(child_id, {"event": "strikes_update", "strikes": child.strikes})
|
||||
return child
|
||||
|
||||
|
||||
@router.delete("/{child_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def delete_child(
|
||||
child_id: int,
|
||||
|
||||
Reference in New Issue
Block a user