Skip to content

Commit 0aac1d1

Browse files
committed
wip: add GET all nominees
1 parent be36ac3 commit 0aac1d1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@
1717
)
1818

1919

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

0 commit comments

Comments
 (0)