Skip to content

Commit 07ff82c

Browse files
committed
Bump FastAPI to 0.89.0
This adds support for function return type annotations to declare the response_model
1 parent a3d26fb commit 07ff82c

File tree

8 files changed

+43
-45
lines changed

8 files changed

+43
-45
lines changed

api/routers/codejams.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
router = APIRouter(prefix="/codejams", tags=["codejams"])
1313

1414

15-
@router.get("/", response_model=list[CodeJamResponse])
16-
async def get_codejams(session: AsyncSession = Depends(get_db_session)) -> list[Jam]:
15+
@router.get("/")
16+
async def get_codejams(session: AsyncSession = Depends(get_db_session)) -> list[CodeJamResponse]:
1717
"""Get all the codejams stored in the database."""
1818
codejams = await session.execute(select(Jam).order_by(desc(Jam.id)))
1919
codejams.unique()
@@ -23,10 +23,9 @@ async def get_codejams(session: AsyncSession = Depends(get_db_session)) -> list[
2323

2424
@router.get(
2525
"/{codejam_id}",
26-
response_model=CodeJamResponse,
2726
responses={404: {"description": "CodeJam could not be found or there is no ongoing code jam."}},
2827
)
29-
async def get_codejam(codejam_id: int, session: AsyncSession = Depends(get_db_session)) -> Jam:
28+
async def get_codejam(codejam_id: int, session: AsyncSession = Depends(get_db_session)) -> CodeJamResponse:
3029
"""
3130
Get a specific codejam stored in the database by ID.
3231
@@ -56,7 +55,7 @@ async def modify_codejam(
5655
name: Optional[str] = None,
5756
ongoing: Optional[bool] = None,
5857
session: AsyncSession = Depends(get_db_session),
59-
) -> None:
58+
) -> CodeJamResponse:
6059
"""Modify the specified codejam to change its name and/or whether it's the ongoing code jam."""
6160
codejam = await session.execute(select(Jam).where(Jam.id == codejam_id))
6261
codejam.unique()
@@ -80,8 +79,8 @@ async def modify_codejam(
8079
return jam
8180

8281

83-
@router.post("/", response_model=CodeJamResponse)
84-
async def create_codejam(codejam: CodeJam, session: AsyncSession = Depends(get_db_session)) -> Jam:
82+
@router.post("/")
83+
async def create_codejam(codejam: CodeJam, session: AsyncSession = Depends(get_db_session)) -> CodeJamResponse:
8584
"""
8685
Create a new codejam and get back the one just created.
8786

api/routers/infractions.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
router = APIRouter(prefix="/infractions", tags=["infractions"])
1111

1212

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

2222
@router.get(
2323
"/{infraction_id}",
24-
response_model=InfractionResponse,
2524
responses={404: {"description": "Infraction could not be found."}},
2625
)
27-
async def get_infraction(infraction_id: int, session: AsyncSession = Depends(get_db_session)) -> DbInfraction:
26+
async def get_infraction(infraction_id: int, session: AsyncSession = Depends(get_db_session)) -> InfractionResponse:
2827
"""Get a specific infraction stored in the database by ID."""
2928
infraction_result = await session.execute(select(DbInfraction).where(DbInfraction.id == infraction_id))
3029
infraction_result.unique()
@@ -36,9 +35,13 @@ async def get_infraction(infraction_id: int, session: AsyncSession = Depends(get
3635

3736

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

api/routers/teams.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ async def ensure_user_exists(user_id: int, session: AsyncSession) -> DbUser:
3535
return user
3636

3737

38-
@router.get("/", response_model=list[TeamResponse])
39-
async def get_teams(current_jam: bool = False, session: AsyncSession = Depends(get_db_session)) -> list[Team]:
38+
@router.get("/")
39+
async def get_teams(current_jam: bool = False, session: AsyncSession = Depends(get_db_session)) -> list[TeamResponse]:
4040
"""Get every code jam team in the database."""
4141
if not current_jam:
4242
teams = await session.execute(select(Team))
@@ -47,10 +47,10 @@ async def get_teams(current_jam: bool = False, session: AsyncSession = Depends(g
4747
return teams.scalars().all()
4848

4949

50-
@router.get("/find", response_model=TeamResponse, responses={404: {"description": "Team could not be found."}})
50+
@router.get("/find", responses={404: {"description": "Team could not be found."}})
5151
async def find_team_by_name(
5252
name: str, jam_id: Optional[int] = None, session: AsyncSession = Depends(get_db_session)
53-
) -> Team:
53+
) -> TeamResponse:
5454
"""Get a specific code jam team by name."""
5555
if jam_id is None:
5656
teams = await session.execute(
@@ -69,14 +69,14 @@ async def find_team_by_name(
6969
return team
7070

7171

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:
72+
@router.get("/{team_id}", responses={404: {"description": "Team could not be found."}})
73+
async def get_team(team_id: int, session: AsyncSession = Depends(get_db_session)) -> TeamResponse:
7474
"""Get a specific code jam team in the database by ID."""
7575
return await ensure_team_exists(team_id, session)
7676

7777

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]:
78+
@router.get("/{team_id}/users", responses={404: {"description": "Team could not be found."}})
79+
async def get_team_users(team_id: int, session: AsyncSession = Depends(get_db_session)) -> list[User]:
8080
"""Get the users of a specific code jam team in the database."""
8181
await ensure_team_exists(team_id, session)
8282

@@ -88,7 +88,6 @@ async def get_team_users(team_id: int, session: AsyncSession = Depends(get_db_se
8888

8989
@router.post(
9090
"/{team_id}/users/{user_id}",
91-
response_model=User,
9291
responses={
9392
404: {
9493
"description": "Team or user could not be found.",
@@ -98,7 +97,7 @@ async def get_team_users(team_id: int, session: AsyncSession = Depends(get_db_se
9897
)
9998
async def add_user_to_team(
10099
team_id: int, user_id: int, is_leader: bool = False, session: AsyncSession = Depends(get_db_session)
101-
) -> TeamUser:
100+
) -> User:
102101
"""Add a user to a specific code jam team in the database."""
103102
await ensure_team_exists(team_id, session)
104103
await ensure_user_exists(user_id, session)

api/routers/users.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ async def get_user_data(session: AsyncSession, user_id: int) -> dict[str, Any]:
4747
return user
4848

4949

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

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

5858

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]:
59+
@router.get("/{user_id}", responses={404: {"description": "User could not be found."}})
60+
async def get_user(user_id: int, session: AsyncSession = Depends(get_db_session)) -> UserResponse:
6161
"""Get a specific user stored in the database by ID."""
6262
user = await session.execute(select(User).where(User.id == user_id))
6363
user.unique()
@@ -68,8 +68,8 @@ async def get_user(user_id: int, session: AsyncSession = Depends(get_db_session)
6868
return await get_user_data(session, user_id)
6969

7070

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]:
71+
@router.post("/{user_id}", responses={400: {"description": "User already exists."}})
72+
async def create_user(user_id: int, session: AsyncSession = Depends(get_db_session)) -> UserResponse:
7373
"""Create a new user with the specified ID to the database."""
7474
user = await session.execute(select(User).where(User.id == user_id))
7575
user.unique()
@@ -86,7 +86,6 @@ async def create_user(user_id: int, session: AsyncSession = Depends(get_db_sessi
8686

8787
@router.get(
8888
"/{user_id}/current_team",
89-
response_model=UserTeamResponse,
9089
responses={
9190
404: {
9291
"description": (
@@ -95,7 +94,7 @@ async def create_user(user_id: int, session: AsyncSession = Depends(get_db_sessi
9594
}
9695
},
9796
)
98-
async def get_current_team(user_id: int, session: AsyncSession = Depends(get_db_session)) -> dict[str, Any]:
97+
async def get_current_team(user_id: int, session: AsyncSession = Depends(get_db_session)) -> UserTeamResponse:
9998
"""Get a user's current team information."""
10099
user = await session.execute(select(User).where(User.id == user_id))
101100
user.unique()

api/routers/winners.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313

1414
@router.get(
1515
"/{jam_id}",
16-
response_model=list[WinnerResponse],
1716
responses={404: {"description": "The specified codejam could not be found."}},
1817
)
19-
async def get_winners(jam_id: int, session: AsyncSession = Depends(get_db_session)) -> list[DbWinner]:
18+
async def get_winners(jam_id: int, session: AsyncSession = Depends(get_db_session)) -> list[WinnerResponse]:
2019
"""Get the top ten winners from the specified codejam."""
2120
jam = await session.execute(select(Jam).where(Jam.id == jam_id))
2221
jam.unique()
@@ -31,7 +30,6 @@ async def get_winners(jam_id: int, session: AsyncSession = Depends(get_db_sessio
3130

3231
@router.post(
3332
"/{jam_id}",
34-
response_model=list[WinnerResponse],
3533
responses={
3634
400: {"description": "The provided winners list is empty or contains duplicate users."},
3735
404: {

main-requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ click==8.1.3 ; python_full_version >= "3.11.0" and python_full_version < "3.12.0
4747
colorama==0.4.6 ; python_full_version >= "3.11.0" and python_full_version < "3.12.0" and sys_platform == "win32" or python_full_version >= "3.11.0" and python_full_version < "3.12.0" and platform_system == "Windows" \
4848
--hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \
4949
--hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6
50-
fastapi==0.88.0 ; python_full_version >= "3.11.0" and python_full_version < "3.12.0" \
51-
--hash=sha256:263b718bb384422fe3d042ffc9a0c8dece5e034ab6586ff034f6b4b1667c3eee \
52-
--hash=sha256:915bf304180a0e7c5605ec81097b7d4cd8826ff87a02bb198e336fb9f3b5ff02
50+
fastapi==0.89.0 ; python_full_version >= "3.11.0" and python_full_version < "3.12.0" \
51+
--hash=sha256:34990132751324c988db7bd15bf43a86f5c8580e58a4438e14b12d72fb0ae1d1 \
52+
--hash=sha256:d8cafbd223b5a3c010119ba61fb246d5fd3b8f4766cfa93f922a416650797976
5353
greenlet==2.0.2 ; python_full_version >= "3.11.0" and platform_machine == "aarch64" and python_full_version < "3.12.0" or python_full_version >= "3.11.0" and platform_machine == "ppc64le" and python_full_version < "3.12.0" or python_full_version >= "3.11.0" and platform_machine == "x86_64" and python_full_version < "3.12.0" or python_full_version >= "3.11.0" and platform_machine == "amd64" and python_full_version < "3.12.0" or python_full_version >= "3.11.0" and platform_machine == "AMD64" and python_full_version < "3.12.0" or python_full_version >= "3.11.0" and platform_machine == "win32" and python_full_version < "3.12.0" or python_full_version >= "3.11.0" and platform_machine == "WIN32" and python_full_version < "3.12.0" \
5454
--hash=sha256:03a8f4f3430c3b3ff8d10a2a86028c660355ab637cee9333d63d66b56f09d52a \
5555
--hash=sha256:0bf60faf0bc2468089bdc5edd10555bab6e85152191df713e2ab1fcc86382b5a \

poetry.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "MIT"
99
python = "3.11.*"
1010

1111
alembic = {version = "1.10.2", extras = ["tz"]}
12-
fastapi = "0.88.0"
12+
fastapi = "0.89.0"
1313
python-decouple = "3.8"
1414
SQLAlchemy = {version = "1.4.45", extras = ["asyncio", "postgresql_asyncpg"]}
1515
uvicorn = {version = "0.21.1", extras = ["standard"]}

0 commit comments

Comments
 (0)