88import elections
99import elections .crud
1010import elections .tables
11+ from elections .models import ElectionModel
1112from elections .tables import Election , NomineeApplication , NomineeInfo , election_types
1213from officers .constants import OfficerPosition
1314from permission .types import ElectionOfficer , WebsiteAdmin
@@ -41,7 +42,8 @@ async def _validate_user(
4142
4243@router .get (
4344 "/list" ,
44- description = "Returns a list of all elections & their status"
45+ description = "Returns a list of all elections & their status" ,
46+ response_model = list [ElectionModel ]
4547)
4648async def list_elections (
4749 _ : Request ,
@@ -68,7 +70,8 @@ async def list_elections(
6870 Retrieves the election data for an election by name.
6971 Returns private details when the time is allowed.
7072 If user is an admin or elections officer, returns computing ids for each candidate as well.
71- """
73+ """ ,
74+ response_model = ElectionModel
7275)
7376async def get_election (
7477 request : Request ,
@@ -168,6 +171,7 @@ def _raise_if_bad_election_data(
168171@router .post (
169172 "/{election_name:str}" ,
170173 description = "Creates an election and places it in the database. Returns election json on success" ,
174+ response_model = ElectionModel
171175)
172176async def create_election (
173177 request : Request ,
@@ -253,7 +257,8 @@ async def create_election(
253257 name produces the same slug.
254258
255259 Returns election json on success.
256- """
260+ """ ,
261+ response_model = ElectionModel
257262)
258263async def update_election (
259264 request : Request ,
@@ -312,7 +317,8 @@ async def update_election(
312317
313318@router .delete (
314319 "/{election_name:str}" ,
315- description = "Deletes an election from the database. Returns whether the election exists after deletion."
320+ description = "Deletes an election from the database. Returns whether the election exists after deletion." ,
321+ response_model = SuccessFailModel
316322)
317323async def delete_election (
318324 request : Request ,
@@ -360,7 +366,7 @@ async def get_election_registrations(
360366 detail = f"election with slug { slugified_name } does not exist"
361367 )
362368
363- registration_list = await elections .crud .get_all_registrations (db_session , computing_id , slugified_name )
369+ registration_list = await elections .crud .get_all_registrations_of_user (db_session , computing_id , slugified_name )
364370 if registration_list is None :
365371 return JSONResponse ([])
366372 return JSONResponse ([
@@ -416,7 +422,7 @@ async def register_in_election(
416422 status_code = status .HTTP_400_BAD_REQUEST ,
417423 detail = "registrations can only be made during the nomination period"
418424 )
419- elif await elections .crud .get_all_registrations (db_session , computing_id , slugified_name ):
425+ elif await elections .crud .get_all_registrations_of_user (db_session , computing_id , slugified_name ):
420426 raise HTTPException (
421427 status_code = status .HTTP_400_BAD_REQUEST ,
422428 detail = "you are already registered in this election"
@@ -484,7 +490,7 @@ async def update_registration(
484490 detail = "speeches can only be updated during the nomination period"
485491 )
486492
487- elif not await elections .crud .get_all_registrations (db_session , ccid_of_registrant , slugified_name ):
493+ elif not await elections .crud .get_all_registrations_of_user (db_session , ccid_of_registrant , slugified_name ):
488494 raise HTTPException (
489495 status_code = status .HTTP_404_NOT_FOUND ,
490496 detail = "applicant not yet registered in this election"
@@ -533,7 +539,7 @@ async def delete_registration(
533539 status_code = status .HTTP_400_BAD_REQUEST ,
534540 detail = "registration can only be revoked during the nomination period"
535541 )
536- elif not await elections .crud .get_all_registrations (db_session , computing_id , slugified_name ):
542+ elif not await elections .crud .get_all_registrations_of_user (db_session , computing_id , slugified_name ):
537543 raise HTTPException (
538544 status_code = status .HTTP_404_NOT_FOUND ,
539545 detail = "you are not yet registered in this election"
0 commit comments