This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from src.db.models.tysc import Team
|
||||
from src.db.session import SessionDep
|
||||
@@ -12,8 +12,16 @@ router = APIRouter()
|
||||
@router.get("/teams")
|
||||
def get_all_teams(db: SessionDep) -> List[TeamResponse]:
|
||||
results: list[TeamResponse] = []
|
||||
sports = db.query(Team).all()
|
||||
for sport in sports:
|
||||
response = to_response(sport)
|
||||
teams = db.query(Team).all()
|
||||
for team in teams:
|
||||
response = to_response(team)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
@router.get("/teams/{team_id}", response_model=TeamResponse)
|
||||
def get_team(team_id: str, db: SessionDep) -> TeamResponse:
|
||||
team = db.get(Team, team_id)
|
||||
if team is None:
|
||||
raise HTTPException(status_code=404, detail="Team could not be found")
|
||||
response = to_response(team)
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user