Add game cancellation feature with cascade deletion and host-only access control

Implemented DELETE `/games/{game_id}` endpoint allowing hosts to cancel games with cascade deletion of sheet states, chips, and memberships. Added `cancelGame` handler in App.jsx to delete game, refresh game list, reset state, and show confirmation snack. Added cancel button to GamePickerCard lobby section (pre-start) and started section (non-finished games) with bilingual confirmation dialog, loading state, and error handling.
This commit is contained in:
2026-08-02 10:46:38 +02:00
parent 565d538c35
commit b20056913b
3 changed files with 61 additions and 5 deletions
+16
View File
@@ -205,6 +205,22 @@ def start_game(req: Request, game_id: str, db: Session = Depends(get_db)):
return {"ok": True, "started": True}
@router.delete("/{game_id}")
def cancel_game(req: Request, game_id: str, db: Session = Depends(get_db)):
uid = require_user(req, db)
g = require_game_member(db, game_id, uid)
if g.host_user_id != uid:
raise HTTPException(403, "only host can cancel the game")
# Remove dependent game state before deleting the game itself.
db.query(SheetState).filter(SheetState.game_id == game_id).delete(synchronize_session=False)
db.query(GameChip).filter(GameChip.game_id == game_id).delete(synchronize_session=False)
db.query(GameMember).filter(GameMember.game_id == game_id).delete(synchronize_session=False)
db.delete(g)
db.commit()
return {"ok": True, "cancelled": True}
@router.get("/{game_id}/chips")
def list_game_chips(req: Request, game_id: str, db: Session = Depends(get_db)):
uid = require_user(req, db)