@@ -21,7 +21,9 @@ async def get_volunteers_by_event(event_id: str) -> list[Registration]:
2121@router .get ("/events/{volunteer_id}" , response_model = list [Event ])
2222async def get_events_by_volunteer (
2323 volunteer_id : str ,
24- status : Annotated [RegistrationStatus | None , Query (description = "Filter by status" )] = None ,
24+ registration_status : Annotated [
25+ RegistrationStatus | None , Query (description = "Filter by status" )
26+ ] = None ,
2527 current_user : Annotated [User , Depends (get_current_user )] = None ,
2628) -> list [Event ]:
2729 volunteer = await volunteer_model .get_volunteer_by_id (volunteer_id )
@@ -37,7 +39,7 @@ async def get_events_by_volunteer(
3739 elif current_user .user_type != UserType .ADMIN :
3840 raise HTTPException (status_code = status .HTTP_403_FORBIDDEN , detail = "Access denied" )
3941
40- return await registration_model .get_events_by_volunteer (volunteer_id , status )
42+ return await registration_model .get_events_by_volunteer (volunteer_id , registration_status )
4143
4244
4345@router .post ("/new" , response_model = Registration )
@@ -57,3 +59,23 @@ async def create_registrion(
5759 )
5860
5961 return await registration_model .create_registration (registration , current_user .entity_id )
62+
63+
64+ @router .put ("/unregister/{registration_id}" , response_model = Registration )
65+ async def unregister_registration (
66+ registration_id : str ,
67+ current_user : Annotated [User , Depends (get_current_user )],
68+ ) -> Registration :
69+ if current_user .user_type != UserType .VOLUNTEER :
70+ raise HTTPException (
71+ status_code = status .HTTP_403_FORBIDDEN ,
72+ detail = "Only volunteers can unregister from events" ,
73+ )
74+
75+ if current_user .entity_id is None :
76+ raise HTTPException (
77+ status_code = status .HTTP_400_BAD_REQUEST ,
78+ detail = "You must be associated with a volunteer profile to unregister from an event" ,
79+ )
80+
81+ return await registration_model .unregister_registration (registration_id , current_user .entity_id )
0 commit comments