Skip to content

Commit a643224

Browse files
committed
wip: add POST nominee
1 parent 4b659be commit a643224

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/nominees/urls.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,47 @@
88
NomineeInfoUpdateParams,
99
)
1010
from nominees.tables import NomineeInfo
11+
from utils.shared_models import DetailModel
1112
from utils.urls import admin_or_raise
1213

1314
router = APIRouter(
1415
prefix="/nominee",
1516
tags=["nominee"],
1617
)
1718

19+
@router.post(
20+
"",
21+
description="Nominee info is always publically tied to election, so be careful!",
22+
response_model=NomineeInfoModel,
23+
responses={
24+
500: { "description": "failed to fetch new nominee", "model": DetailModel }
25+
},
26+
operation_id="create_nominee"
27+
)
28+
async def create_nominee(
29+
request: Request,
30+
db_session: database.DBSession,
31+
body: NomineeInfoModel
32+
):
33+
await admin_or_raise(request, db_session)
34+
await nominees.crud.create_nominee_info(db_session, NomineeInfo(
35+
computing_id=body.computing_id,
36+
full_name=body.full_name,
37+
linked_in=body.linked_in,
38+
instagram=body.instagram,
39+
email=body.email,
40+
discord_username=body.discord_username,
41+
))
42+
43+
nominee_info = await nominees.crud.get_nominee_info(db_session, body.computing_id)
44+
if nominee_info is None:
45+
raise HTTPException(
46+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
47+
detail="couldn't fetch newly created nominee"
48+
)
49+
50+
return JSONResponse(nominee_info)
51+
1852
@router.get(
1953
"/{computing_id:str}",
2054
description="Nominee info is always publically tied to election, so be careful!",
@@ -71,6 +105,7 @@ async def provide_nominee_info(
71105
if body.discord_username is not None:
72106
updated_data["discord_username"] = body.discord_username
73107

108+
# TODO: Look into using something built into SQLAlchemy/Pydantic for better entry updates
74109
existing_info = await nominees.crud.get_nominee_info(db_session, computing_id)
75110
# if not already existing, create it
76111
if not existing_info:

0 commit comments

Comments
 (0)