@@ -33,8 +33,12 @@ async def get_user_data(session: AsyncSession, user_id: int) -> dict[str, Any]:
3333
3434 participation_history .append (
3535 {
36- "jam_id" : user_team .team .jam .id , "top_10" : top_10 , "first_place" : first_place ,
37- "team_id" : user_team .team .id , "is_leader" : user_team .is_leader , "infractions" : infractions
36+ "jam_id" : user_team .team .jam .id ,
37+ "top_10" : top_10 ,
38+ "first_place" : first_place ,
39+ "team_id" : user_team .team .id ,
40+ "is_leader" : user_team .is_leader ,
41+ "infractions" : infractions ,
3842 }
3943 )
4044
@@ -52,15 +56,7 @@ async def get_users(session: AsyncSession = Depends(get_db_session)) -> list[dic
5256 return [await get_user_data (session , user ) for user in users .scalars ().all ()]
5357
5458
55- @router .get (
56- "/{user_id}" ,
57- response_model = UserResponse ,
58- responses = {
59- 404 : {
60- "description" : "User could not be found."
61- }
62- }
63- )
59+ @router .get ("/{user_id}" , response_model = UserResponse , responses = {404 : {"description" : "User could not be found." }})
6460async def get_user (user_id : int , session : AsyncSession = Depends (get_db_session )) -> dict [str , Any ]:
6561 """Get a specific user stored in the database by ID."""
6662 user = await session .execute (select (User ).where (User .id == user_id ))
@@ -72,15 +68,7 @@ async def get_user(user_id: int, session: AsyncSession = Depends(get_db_session)
7268 return await get_user_data (session , user_id )
7369
7470
75- @router .post (
76- "/{user_id}" ,
77- response_model = UserResponse ,
78- responses = {
79- 400 : {
80- "description" : "User already exists."
81- }
82- }
83- )
71+ @router .post ("/{user_id}" , response_model = UserResponse , responses = {400 : {"description" : "User already exists." }})
8472async def create_user (user_id : int , session : AsyncSession = Depends (get_db_session )) -> dict [str , Any ]:
8573 """Create a new user with the specified ID to the database."""
8674 user = await session .execute (select (User ).where (User .id == user_id ))
@@ -102,12 +90,10 @@ async def create_user(user_id: int, session: AsyncSession = Depends(get_db_sessi
10290 responses = {
10391 404 : {
10492 "description" : (
105- "User not found, "
106- "there is no ongoing code jam or "
107- "user isn't participating in current code jam."
93+ "User not found, " "there is no ongoing code jam or " "user isn't participating in current code jam."
10894 )
10995 }
110- }
96+ },
11197)
11298async def get_current_team (user_id : int , session : AsyncSession = Depends (get_db_session )) -> dict [str , Any ]:
11399 """Get a user's current team information."""
@@ -117,16 +103,12 @@ async def get_current_team(user_id: int, session: AsyncSession = Depends(get_db_
117103 if not user .scalars ().one_or_none ():
118104 raise HTTPException (status_code = 404 , detail = "User with specified ID could not be found." )
119105
120- ongoing_jam = (
121- await session .execute (select (Jam ).where (Jam .ongoing == True ))
122- ).unique ().scalars ().one_or_none ()
106+ ongoing_jam = (await session .execute (select (Jam ).where (Jam .ongoing == True ))).unique ().scalars ().one_or_none ()
123107
124108 if not ongoing_jam :
125109 raise HTTPException (status_code = 404 , detail = "There is no ongoing codejam." )
126110
127- user_teams = (
128- await session .execute (select (TeamUser ).where (TeamUser .user_id == user_id ))
129- ).unique ().scalars ().all ()
111+ user_teams = (await session .execute (select (TeamUser ).where (TeamUser .user_id == user_id ))).unique ().scalars ().all ()
130112
131113 current_team = None
132114 for user_team in user_teams :
@@ -135,9 +117,6 @@ async def get_current_team(user_id: int, session: AsyncSession = Depends(get_db_
135117 break
136118
137119 if not current_team :
138- raise HTTPException (
139- status_code = 404 ,
140- detail = "User with specified ID isn't participating in ongoing codejam."
141- )
120+ raise HTTPException (status_code = 404 , detail = "User with specified ID isn't participating in ongoing codejam." )
142121
143122 return current_team
0 commit comments