|
8 | 8 | NomineeInfoUpdateParams, |
9 | 9 | ) |
10 | 10 | from nominees.tables import NomineeInfo |
| 11 | +from utils.shared_models import DetailModel |
11 | 12 | from utils.urls import admin_or_raise |
12 | 13 |
|
13 | 14 | router = APIRouter( |
14 | 15 | prefix="/nominee", |
15 | 16 | tags=["nominee"], |
16 | 17 | ) |
17 | 18 |
|
| 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 | + |
18 | 52 | @router.get( |
19 | 53 | "/{computing_id:str}", |
20 | 54 | description="Nominee info is always publically tied to election, so be careful!", |
@@ -71,6 +105,7 @@ async def provide_nominee_info( |
71 | 105 | if body.discord_username is not None: |
72 | 106 | updated_data["discord_username"] = body.discord_username |
73 | 107 |
|
| 108 | + # TODO: Look into using something built into SQLAlchemy/Pydantic for better entry updates |
74 | 109 | existing_info = await nominees.crud.get_nominee_info(db_session, computing_id) |
75 | 110 | # if not already existing, create it |
76 | 111 | if not existing_info: |
|
0 commit comments