11from typing import Optional
22
3- from fastapi import APIRouter , Depends , HTTPException , Response
3+ from fastapi import APIRouter , HTTPException , Response
44from sqlalchemy import func
55from sqlalchemy .ext .asyncio import AsyncSession
66from sqlalchemy .future import select
77
8- from api .database import Jam , Team , TeamUser
8+ from api .database import DBSession , Jam , Team , TeamUser
99from api .database import User as DbUser
10- from api .dependencies import get_db_session
1110from api .models import TeamResponse , User
1211
1312router = APIRouter (prefix = "/teams" , tags = ["teams" ])
@@ -35,8 +34,8 @@ async def ensure_user_exists(user_id: int, session: AsyncSession) -> DbUser:
3534 return user
3635
3736
38- @router .get ("/" , response_model = list [ TeamResponse ] )
39- async def get_teams (current_jam : bool = False , session : AsyncSession = Depends ( get_db_session )) -> list [Team ]:
37+ @router .get ("/" )
38+ async def get_teams (session : DBSession , current_jam : bool = False ) -> list [TeamResponse ]:
4039 """Get every code jam team in the database."""
4140 if not current_jam :
4241 teams = await session .execute (select (Team ))
@@ -47,10 +46,12 @@ async def get_teams(current_jam: bool = False, session: AsyncSession = Depends(g
4746 return teams .scalars ().all ()
4847
4948
50- @router .get ("/find" , response_model = TeamResponse , responses = {404 : {"description" : "Team could not be found." }})
49+ @router .get ("/find" , responses = {404 : {"description" : "Team could not be found." }})
5150async def find_team_by_name (
52- name : str , jam_id : Optional [int ] = None , session : AsyncSession = Depends (get_db_session )
53- ) -> Team :
51+ name : str ,
52+ session : DBSession ,
53+ jam_id : Optional [int ] = None ,
54+ ) -> TeamResponse :
5455 """Get a specific code jam team by name."""
5556 if jam_id is None :
5657 teams = await session .execute (
@@ -69,14 +70,14 @@ async def find_team_by_name(
6970 return team
7071
7172
72- @router .get ("/{team_id}" , response_model = TeamResponse , responses = {404 : {"description" : "Team could not be found." }})
73- async def get_team (team_id : int , session : AsyncSession = Depends ( get_db_session )) -> Team :
73+ @router .get ("/{team_id}" , responses = {404 : {"description" : "Team could not be found." }})
74+ async def get_team (team_id : int , session : DBSession ) -> TeamResponse :
7475 """Get a specific code jam team in the database by ID."""
7576 return await ensure_team_exists (team_id , session )
7677
7778
78- @router .get ("/{team_id}/users" , response_model = list [ User ], responses = {404 : {"description" : "Team could not be found." }})
79- async def get_team_users (team_id : int , session : AsyncSession = Depends ( get_db_session )) -> list [TeamUser ]:
79+ @router .get ("/{team_id}/users" , responses = {404 : {"description" : "Team could not be found." }})
80+ async def get_team_users (team_id : int , session : DBSession ) -> list [User ]:
8081 """Get the users of a specific code jam team in the database."""
8182 await ensure_team_exists (team_id , session )
8283
@@ -88,17 +89,14 @@ async def get_team_users(team_id: int, session: AsyncSession = Depends(get_db_se
8889
8990@router .post (
9091 "/{team_id}/users/{user_id}" ,
91- response_model = User ,
9292 responses = {
9393 404 : {
9494 "description" : "Team or user could not be found." ,
9595 },
9696 400 : {"description" : "This user is already on the team." },
9797 },
9898)
99- async def add_user_to_team (
100- team_id : int , user_id : int , is_leader : bool = False , session : AsyncSession = Depends (get_db_session )
101- ) -> TeamUser :
99+ async def add_user_to_team (team_id : int , user_id : int , session : DBSession , is_leader : bool = False ) -> User :
102100 """Add a user to a specific code jam team in the database."""
103101 await ensure_team_exists (team_id , session )
104102 await ensure_user_exists (user_id , session )
@@ -129,7 +127,9 @@ async def add_user_to_team(
129127 },
130128)
131129async def remove_user_from_team (
132- team_id : int , user_id : int , session : AsyncSession = Depends (get_db_session )
130+ team_id : int ,
131+ user_id : int ,
132+ session : DBSession ,
133133) -> Response :
134134 """Remove a user from a specific code jam team in the database."""
135135 await ensure_team_exists (team_id , session )
0 commit comments