Skip to content

Commit e4035bd

Browse files
committed
wip: add GET all nominees
1 parent a643224 commit e4035bd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/nominees/crud.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
from collections.abc import Sequence
2+
13
import sqlalchemy
24
from sqlalchemy.ext.asyncio import AsyncSession
35

46
from nominees.tables import NomineeInfo
57

68

9+
async def get_all_nominees(
10+
db_session: AsyncSession,
11+
) -> Sequence[NomineeInfo]:
12+
nominees = (await db_session.scalars(
13+
sqlalchemy
14+
.select(NomineeInfo)
15+
)).all()
16+
return nominees
17+
718
async def get_nominee_info(
819
db_session: AsyncSession,
920
computing_id: str,

src/nominees/urls.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@
1616
tags=["nominee"],
1717
)
1818

19+
@router.get(
20+
"",
21+
description="Get all nominees",
22+
response_model=list[NomineeInfoModel],
23+
responses={
24+
403: { "description": "need to be an admin", "model": DetailModel }
25+
},
26+
operation_id="create_nominee"
27+
)
28+
async def get_all_nominees(
29+
request: Request,
30+
db_session: database.DBSession,
31+
):
32+
# Putting this behind a wall since there is private information here
33+
await admin_or_raise(request, db_session)
34+
nominees_list = await nominees.crud.get_all_nominees(db_session)
35+
36+
return JSONResponse([
37+
item.serialize() for item in nominees_list
38+
])
39+
1940
@router.post(
2041
"",
2142
description="Nominee info is always publically tied to election, so be careful!",

0 commit comments

Comments
 (0)