Skip to content

Commit 5011a22

Browse files
Merge pull request #27 from python-discord/update-deps
Update deps
2 parents 31a37b5 + e0b413e commit 5011a22

File tree

11 files changed

+989
-842
lines changed

11 files changed

+989
-842
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.3.0
3+
rev: v4.4.0
44
hooks:
55
- id: check-merge-conflict
66
- id: check-toml
@@ -11,18 +11,18 @@ repos:
1111
args: [--markdown-linebreak-ext=md]
1212

1313
- repo: https://github.com/pre-commit/pygrep-hooks
14-
rev: v1.9.0
14+
rev: v1.10.0
1515
hooks:
1616
- id: python-check-blanket-noqa
1717

1818
- repo: https://github.com/pycqa/isort
19-
rev: 5.10.1
19+
rev: 5.12.0
2020
hooks:
2121
- id: isort
2222
name: isort (python)
2323

2424
- repo: https://github.com/python-poetry/poetry
25-
rev: '1.2.2'
25+
rev: 1.4.1
2626
hooks:
2727
- id: poetry-check
2828
- id: poetry-export

api/database.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
from typing import Annotated
2+
3+
from fastapi import Depends
14
from sqlalchemy import BigInteger, Boolean, Column, Enum, ForeignKey, Index, Integer, PrimaryKeyConstraint, Text, text
25
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
36
from sqlalchemy.ext.declarative import declarative_base
47
from sqlalchemy.orm import relationship, sessionmaker
58

69
from api.constants import Config
10+
from api.dependencies import get_db_session
711

812
engine = create_async_engine(Config.DATABASE_URL)
913
Base = declarative_base()
1014

1115
Session = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)
16+
DBSession = Annotated[AsyncSession, Depends(get_db_session)]
1217

1318

1419
class TeamUser(Base):

api/routers/codejams.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
from typing import Optional
22

3-
from fastapi import APIRouter, Depends, HTTPException
3+
from fastapi import APIRouter, HTTPException
44
from sqlalchemy import desc, update
5-
from sqlalchemy.ext.asyncio import AsyncSession
65
from sqlalchemy.future import select
76

8-
from api.database import Jam, Team, TeamUser, User
9-
from api.dependencies import get_db_session
7+
from api.database import DBSession, Jam, Team, TeamUser, User
108
from api.models import CodeJam, CodeJamResponse
119

1210
router = APIRouter(prefix="/codejams", tags=["codejams"])
1311

1412

15-
@router.get("/", response_model=list[CodeJamResponse])
16-
async def get_codejams(session: AsyncSession = Depends(get_db_session)) -> list[Jam]:
13+
@router.get("/")
14+
async def get_codejams(session: DBSession) -> list[CodeJamResponse]:
1715
"""Get all the codejams stored in the database."""
1816
codejams = await session.execute(select(Jam).order_by(desc(Jam.id)))
1917
codejams.unique()
@@ -23,10 +21,9 @@ async def get_codejams(session: AsyncSession = Depends(get_db_session)) -> list[
2321

2422
@router.get(
2523
"/{codejam_id}",
26-
response_model=CodeJamResponse,
2724
responses={404: {"description": "CodeJam could not be found or there is no ongoing code jam."}},
2825
)
29-
async def get_codejam(codejam_id: int, session: AsyncSession = Depends(get_db_session)) -> Jam:
26+
async def get_codejam(codejam_id: int, session: DBSession) -> CodeJamResponse:
3027
"""
3128
Get a specific codejam stored in the database by ID.
3229
@@ -53,10 +50,10 @@ async def get_codejam(codejam_id: int, session: AsyncSession = Depends(get_db_se
5350
@router.patch("/{codejam_id}", responses={404: {"description": "Code Jam with specified ID does not exist."}})
5451
async def modify_codejam(
5552
codejam_id: int,
53+
session: DBSession,
5654
name: Optional[str] = None,
5755
ongoing: Optional[bool] = None,
58-
session: AsyncSession = Depends(get_db_session),
59-
) -> None:
56+
) -> CodeJamResponse:
6057
"""Modify the specified codejam to change its name and/or whether it's the ongoing code jam."""
6158
codejam = await session.execute(select(Jam).where(Jam.id == codejam_id))
6259
codejam.unique()
@@ -80,8 +77,8 @@ async def modify_codejam(
8077
return jam
8178

8279

83-
@router.post("/", response_model=CodeJamResponse)
84-
async def create_codejam(codejam: CodeJam, session: AsyncSession = Depends(get_db_session)) -> Jam:
80+
@router.post("/")
81+
async def create_codejam(codejam: CodeJam, session: DBSession) -> CodeJamResponse:
8582
"""
8683
Create a new codejam and get back the one just created.
8784

api/routers/infractions.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from fastapi import APIRouter, Depends, HTTPException
2-
from sqlalchemy.ext.asyncio import AsyncSession
1+
from fastapi import APIRouter, HTTPException
32
from sqlalchemy.future import select
43

4+
from api.database import DBSession
55
from api.database import Infraction as DbInfraction
66
from api.database import Jam, User
7-
from api.dependencies import get_db_session
87
from api.models import Infraction, InfractionResponse
98

109
router = APIRouter(prefix="/infractions", tags=["infractions"])
1110

1211

13-
@router.get("/", response_model=list[InfractionResponse])
14-
async def get_infractions(session: AsyncSession = Depends(get_db_session)) -> list[DbInfraction]:
12+
@router.get("/")
13+
async def get_infractions(session: DBSession) -> list[InfractionResponse]:
1514
"""Get every infraction stored in the database."""
1615
infractions = await session.execute(select(DbInfraction))
1716
infractions.unique()
@@ -21,10 +20,9 @@ async def get_infractions(session: AsyncSession = Depends(get_db_session)) -> li
2120

2221
@router.get(
2322
"/{infraction_id}",
24-
response_model=InfractionResponse,
2523
responses={404: {"description": "Infraction could not be found."}},
2624
)
27-
async def get_infraction(infraction_id: int, session: AsyncSession = Depends(get_db_session)) -> DbInfraction:
25+
async def get_infraction(infraction_id: int, session: DBSession) -> InfractionResponse:
2826
"""Get a specific infraction stored in the database by ID."""
2927
infraction_result = await session.execute(select(DbInfraction).where(DbInfraction.id == infraction_id))
3028
infraction_result.unique()
@@ -36,9 +34,13 @@ async def get_infraction(infraction_id: int, session: AsyncSession = Depends(get
3634

3735

3836
@router.post(
39-
"/", response_model=InfractionResponse, responses={404: {"Description": "Jam ID or User ID could not be found."}}
37+
"/",
38+
responses={404: {"Description": "Jam ID or User ID could not be found."}},
4039
)
41-
async def create_infraction(infraction: Infraction, session: AsyncSession = Depends(get_db_session)) -> DbInfraction:
40+
async def create_infraction(
41+
infraction: Infraction,
42+
session: DBSession,
43+
) -> InfractionResponse:
4244
"""Add an infraction for a user to the database."""
4345
jam_id = (await session.execute(select(Jam.id).where(Jam.id == infraction.jam_id))).scalars().one_or_none()
4446

api/routers/teams.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from typing import Optional
22

3-
from fastapi import APIRouter, Depends, HTTPException, Response
3+
from fastapi import APIRouter, HTTPException, Response
44
from sqlalchemy import func
55
from sqlalchemy.ext.asyncio import AsyncSession
66
from sqlalchemy.future import select
77

8-
from api.database import Jam, Team, TeamUser
8+
from api.database import DBSession, Jam, Team, TeamUser
99
from api.database import User as DbUser
10-
from api.dependencies import get_db_session
1110
from api.models import TeamResponse, User
1211

1312
router = 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."}})
5150
async 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
)
131129
async 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)

api/routers/users.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from typing import Any
22

3-
from fastapi import APIRouter, Depends, HTTPException
3+
from fastapi import APIRouter, HTTPException
44
from sqlalchemy.ext.asyncio import AsyncSession
55
from sqlalchemy.future import select
66

7-
from api.database import Jam, TeamUser, User
8-
from api.dependencies import get_db_session
7+
from api.database import DBSession, Jam, TeamUser, User
98
from api.models import UserResponse, UserTeamResponse
109

1110
router = APIRouter(prefix="/users", tags=["users"])
@@ -47,17 +46,17 @@ async def get_user_data(session: AsyncSession, user_id: int) -> dict[str, Any]:
4746
return user
4847

4948

50-
@router.get("/", response_model=list[UserResponse])
51-
async def get_users(session: AsyncSession = Depends(get_db_session)) -> list[dict[str, Any]]:
49+
@router.get("/")
50+
async def get_users(session: DBSession) -> list[UserResponse]:
5251
"""Get information about all the users stored in the database."""
5352
users = await session.execute(select(User.id))
5453
users.unique()
5554

5655
return [await get_user_data(session, user) for user in users.scalars().all()]
5756

5857

59-
@router.get("/{user_id}", response_model=UserResponse, responses={404: {"description": "User could not be found."}})
60-
async def get_user(user_id: int, session: AsyncSession = Depends(get_db_session)) -> dict[str, Any]:
58+
@router.get("/{user_id}", responses={404: {"description": "User could not be found."}})
59+
async def get_user(user_id: int, session: DBSession) -> UserResponse:
6160
"""Get a specific user stored in the database by ID."""
6261
user = await session.execute(select(User).where(User.id == user_id))
6362
user.unique()
@@ -68,8 +67,8 @@ async def get_user(user_id: int, session: AsyncSession = Depends(get_db_session)
6867
return await get_user_data(session, user_id)
6968

7069

71-
@router.post("/{user_id}", response_model=UserResponse, responses={400: {"description": "User already exists."}})
72-
async def create_user(user_id: int, session: AsyncSession = Depends(get_db_session)) -> dict[str, Any]:
70+
@router.post("/{user_id}", responses={400: {"description": "User already exists."}})
71+
async def create_user(user_id: int, session: DBSession) -> UserResponse:
7372
"""Create a new user with the specified ID to the database."""
7473
user = await session.execute(select(User).where(User.id == user_id))
7574
user.unique()
@@ -86,7 +85,6 @@ async def create_user(user_id: int, session: AsyncSession = Depends(get_db_sessi
8685

8786
@router.get(
8887
"/{user_id}/current_team",
89-
response_model=UserTeamResponse,
9088
responses={
9189
404: {
9290
"description": (
@@ -95,7 +93,7 @@ async def create_user(user_id: int, session: AsyncSession = Depends(get_db_sessi
9593
}
9694
},
9795
)
98-
async def get_current_team(user_id: int, session: AsyncSession = Depends(get_db_session)) -> dict[str, Any]:
96+
async def get_current_team(user_id: int, session: DBSession) -> UserTeamResponse:
9997
"""Get a user's current team information."""
10098
user = await session.execute(select(User).where(User.id == user_id))
10199
user.unique()

api/routers/winners.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
from fastapi import APIRouter, Depends, HTTPException
1+
from fastapi import APIRouter, HTTPException
22
from sqlalchemy import func
3-
from sqlalchemy.ext.asyncio import AsyncSession
43
from sqlalchemy.future import select
54

6-
from api.database import Jam, User
5+
from api.database import DBSession, Jam, User
76
from api.database import Winner as DbWinner
8-
from api.dependencies import get_db_session
97
from api.models import Winner, WinnerResponse
108

119
router = APIRouter(prefix="/winners", tags=["winners"])
1210

1311

1412
@router.get(
1513
"/{jam_id}",
16-
response_model=list[WinnerResponse],
1714
responses={404: {"description": "The specified codejam could not be found."}},
1815
)
19-
async def get_winners(jam_id: int, session: AsyncSession = Depends(get_db_session)) -> list[DbWinner]:
16+
async def get_winners(jam_id: int, session: DBSession) -> list[WinnerResponse]:
2017
"""Get the top ten winners from the specified codejam."""
2118
jam = await session.execute(select(Jam).where(Jam.id == jam_id))
2219
jam.unique()
@@ -31,7 +28,6 @@ async def get_winners(jam_id: int, session: AsyncSession = Depends(get_db_sessio
3128

3229
@router.post(
3330
"/{jam_id}",
34-
response_model=list[WinnerResponse],
3531
responses={
3632
400: {"description": "The provided winners list is empty or contains duplicate users."},
3733
404: {
@@ -40,9 +36,7 @@ async def get_winners(jam_id: int, session: AsyncSession = Depends(get_db_sessio
4036
409: {"description": "One or more users are already a winner in the specified codejam."},
4137
},
4238
)
43-
async def create_winners(
44-
jam_id: int, winners: list[Winner], session: AsyncSession = Depends(get_db_session)
45-
) -> list[WinnerResponse]:
39+
async def create_winners(jam_id: int, winners: list[Winner], session: DBSession) -> list[WinnerResponse]:
4640
"""Add the top ten winners to the specified codejam."""
4741
jam = await session.execute(select(Jam).where(Jam.id == jam_id))
4842
jam.unique()

0 commit comments

Comments
 (0)