@@ -257,7 +257,7 @@ async def delete_election(
257257 "/register/{election_name:str}" ,
258258 description = "get your election registration(s)"
259259)
260- async def get_election_registration (
260+ async def get_election_registrations (
261261 request : Request ,
262262 db_session : database .DBSession ,
263263 election_name : str
@@ -289,19 +289,25 @@ async def get_election_registration(
289289
290290@router .post (
291291 "/register/{election_name:str}" ,
292- description = "register for the election, but doesn't set any speeches or positions. "
292+ description = "register for a specific position in this election, but doesn't set a speech "
293293)
294294async def register_in_election (
295295 request : Request ,
296296 db_session : database .DBSession ,
297- election_name : str
297+ election_name : str ,
298+ position : str
298299):
299300 logged_in , _ , computing_id = await is_logged_in (request , db_session )
300301 if not logged_in :
301302 raise HTTPException (
302303 status_code = status .HTTP_401_UNAUTHORIZED ,
303304 detail = "must be logged in to register in election"
304305 )
306+ elif position not in OfficerPosition .position_list ():
307+ raise HTTPException (
308+ status_code = status .HTTP_400_BAD_REQUEST ,
309+ detail = f"invalid position { position } "
310+ )
305311
306312 election_slug = _slugify (election_name )
307313 if await get_election (db_session , election_slug ) is None :
@@ -321,20 +327,20 @@ async def register_in_election(
321327 await elections .crud .add_registration (db_session , NomineeApplication (
322328 computing_id = computing_id ,
323329 nominee_election = election_slug ,
324- speech = None ,
325- position = None ,
330+ position = position ,
331+ speech = None
326332 ))
327333
328334@router .patch (
329335 "/register/{election_name:str}" ,
330- description = "update your registration for an election"
336+ description = "update your speech for a specific position for an election"
331337)
332338async def update_registration (
333339 request : Request ,
334340 db_session : database .DBSession ,
335341 election_name : str ,
336- speech : str | None ,
337342 position : str ,
343+ speech : str | None ,
338344):
339345 logged_in , _ , computing_id = await is_logged_in (request , db_session )
340346 if not logged_in :
@@ -344,7 +350,7 @@ async def update_registration(
344350 )
345351 elif position not in OfficerPosition .position_list ():
346352 raise HTTPException (
347- status_code = status .HTTP_401_UNAUTHORIZED ,
353+ status_code = status .HTTP_400_BAD_REQUEST ,
348354 detail = f"invalid position { position } "
349355 )
350356
@@ -363,25 +369,31 @@ async def update_registration(
363369 await elections .crud .update_registration (db_session , NomineeApplication (
364370 computing_id = computing_id ,
365371 nominee_election = election_slug ,
366- speech = speech ,
367372 position = position ,
373+ speech = speech
368374 ))
369375
370376@router .delete (
371377 "/register/{election_name:str}" ,
372- description = "revoke your registration in the election"
378+ description = "revoke your registration for a specific position in this election"
373379)
374380async def delete_registration (
375381 request : Request ,
376382 db_session : database .DBSession ,
377- election_name : str
383+ election_name : str ,
384+ position : str ,
378385):
379386 logged_in , _ , computing_id = await is_logged_in (request , db_session )
380387 if not logged_in :
381388 raise HTTPException (
382389 status_code = status .HTTP_401_UNAUTHORIZED ,
383390 detail = "must be logged in to delete election registeration"
384391 )
392+ elif position not in OfficerPosition .position_list ():
393+ raise HTTPException (
394+ status_code = status .HTTP_400_BAD_REQUEST ,
395+ detail = f"invalid position { position } "
396+ )
385397
386398 election_slug = _slugify (election_name )
387399 if await get_election (db_session , election_slug ) is None :
@@ -395,4 +407,4 @@ async def delete_registration(
395407 detail = "you are not yet registered in this election"
396408 )
397409
398- await elections .crud .delete_registration (db_session , computing_id , election_slug )
410+ await elections .crud .delete_registration (db_session , computing_id , election_slug , position )
0 commit comments