Spaces:
Running
Running
sghorbal commited on
Commit ·
9e76472
1
Parent(s): fb9b2b8
expose players by api
Browse files- src/main.py +19 -0
src/main.py
CHANGED
|
@@ -41,6 +41,7 @@ from src.entity.match import (
|
|
| 41 |
MatchApiBase,
|
| 42 |
MatchApiDetail
|
| 43 |
)
|
|
|
|
| 44 |
from src.entity.tournament import Tournament
|
| 45 |
from src.repository.common import get_session
|
| 46 |
from src.repository.sql import list_tournaments as _list_tournaments
|
|
@@ -242,6 +243,24 @@ async def list_tournament_names(
|
|
| 242 |
|
| 243 |
return output
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
# Get all the matches from a tournament
|
| 246 |
@app.get("/tournament/matches", tags=["tournament"], description="Get all the matches from a tournament", response_model=List[MatchApiBase])
|
| 247 |
async def search_tournament_matches(
|
|
|
|
| 41 |
MatchApiBase,
|
| 42 |
MatchApiDetail
|
| 43 |
)
|
| 44 |
+
from src.entity.player import Player, PlayerApiDetail
|
| 45 |
from src.entity.tournament import Tournament
|
| 46 |
from src.repository.common import get_session
|
| 47 |
from src.repository.sql import list_tournaments as _list_tournaments
|
|
|
|
| 243 |
|
| 244 |
return output
|
| 245 |
|
| 246 |
+
# Get a player
|
| 247 |
+
@app.get("/player/{player_id}", tags=["player"], description="Get a player from the database", response_model=PlayerApiDetail)
|
| 248 |
+
async def get_player(
|
| 249 |
+
player_id: int,
|
| 250 |
+
session: Annotated[Session, Depends(get_session)]
|
| 251 |
+
):
|
| 252 |
+
"""
|
| 253 |
+
Get a player from the database
|
| 254 |
+
"""
|
| 255 |
+
player = session.query(Player).filter(Player.id == player_id).first()
|
| 256 |
+
if not player:
|
| 257 |
+
raise HTTPException(
|
| 258 |
+
status_code=HTTP_404_NOT_FOUND,
|
| 259 |
+
detail=f"Player {player_id} not found"
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
return player
|
| 263 |
+
|
| 264 |
# Get all the matches from a tournament
|
| 265 |
@app.get("/tournament/matches", tags=["tournament"], description="Get all the matches from a tournament", response_model=List[MatchApiBase])
|
| 266 |
async def search_tournament_matches(
|