incognitolm commited on
Commit
5dda4a8
·
verified ·
1 Parent(s): 6913be1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -23
app.py CHANGED
@@ -52,24 +52,6 @@ async def test():
52
  async def getGames():
53
  return {"success": True, "data": games}
54
 
55
- @app.get("/api/gameData")
56
- async def get_game_data(pin: str):
57
- game = games.get(pin)
58
- if not game:
59
- raise HTTPException(status_code=404, detail="Game not found.")
60
- return {"success": True, "game": game}
61
-
62
- @app.put("/api/gameData")
63
- async def update_game_data(request: Request):
64
- data = await request.json()
65
- pin = data.get("pin")
66
-
67
- if not pin or pin not in games:
68
- raise HTTPException(status_code=404, detail="Game not found.")
69
-
70
- games[pin].update(data)
71
- return {"success": True, "message": "Game updated successfully!"}
72
-
73
  @app.get("/api/getGameStatus")
74
  async def get_game_status(pin: str):
75
  game = games.get(pin)
@@ -451,6 +433,12 @@ async def start_game(request: Request):
451
  async def delete_game(request: Request):
452
  data = await request.json()
453
  pin = data.get("pin")
 
 
 
 
 
 
454
 
455
  if not pin:
456
  raise HTTPException(status_code=400, detail="PIN is required.")
@@ -459,11 +447,7 @@ async def delete_game(request: Request):
459
  if not game:
460
  raise HTTPException(status_code=404, detail="Game not found.")
461
 
462
- # Only allow deletion if there is exactly one player in the game.
463
- if len(game["players"]) != 1:
464
- raise HTTPException(status_code=400, detail="Game cannot be deleted unless there is only one player left.")
465
-
466
- del games[pin]
467
  return {"success": True, "message": "Game deleted successfully!"}
468
 
469
  def generate_cards(numofcards):
 
52
  async def getGames():
53
  return {"success": True, "data": games}
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  @app.get("/api/getGameStatus")
56
  async def get_game_status(pin: str):
57
  game = games.get(pin)
 
433
  async def delete_game(request: Request):
434
  data = await request.json()
435
  pin = data.get("pin")
436
+ newPin = random.randint(100000, 999999)
437
+ newGame = games.get(newPin)
438
+
439
+ while newGame:
440
+ newPin = random.randint(100000, 999999)
441
+ newGame = games.get(newPin)
442
 
443
  if not pin:
444
  raise HTTPException(status_code=400, detail="PIN is required.")
 
447
  if not game:
448
  raise HTTPException(status_code=404, detail="Game not found.")
449
 
450
+ games[pin] = {"gameEnded": True, "newPin": newPin}
 
 
 
 
451
  return {"success": True, "message": "Game deleted successfully!"}
452
 
453
  def generate_cards(numofcards):