Skip to content

Commit

Permalink
added create room endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejWojt committed Dec 13, 2023
1 parent e033713 commit 74e622f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions backend/src/routers/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fastapi import APIRouter

from fastapi import APIRouter, Body, HTTPException
from src.dependencies import get_manager

router = APIRouter()
Expand All @@ -22,3 +21,17 @@ async def get_games(started: bool):
return {"games": games}
else:
return {"message": "all games has already started"}


@router.post("/api/v1/games")
async def create_game(
room_name: str = Body(...),
max_players: int = Body(...),
password: str = Body(None),
):
try:
manager = await get_manager().__anext__()
manager.add_new_game(max_players, room_name, password)
return {"status": "Game created successfully"}
except ValueError as e:
raise HTTPException(status_code=403, detail=str(e))

0 comments on commit 74e622f

Please sign in to comment.