2121
2222# In-memory activity database
2323activities = {
24- "Chess Club" : {
25- "description" : "Learn strategies and compete in chess tournaments" ,
26- "schedule" : "Fridays, 3:30 PM - 5:00 PM" ,
27- "max_participants" : 12 ,
28- "participants" : ["michael@mergington.edu" , "daniel@mergington.edu" ]
29- },
30- "Programming Class" : {
31- "description" : "Learn programming fundamentals and build software projects" ,
32- "schedule" : "Tuesdays and Thursdays, 3:30 PM - 4:30 PM" ,
33- "max_participants" : 20 ,
34- "participants" : ["emma@mergington.edu" , "sophia@mergington.edu" ]
35- },
36- "Gym Class" : {
37- "description" : "Physical education and sports activities" ,
38- "schedule" : "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM" ,
39- "max_participants" : 30 ,
40- "participants" : ["john@mergington.edu" , "olivia@mergington.edu" ]
41- },
42- "Soccer Team" : {
43- "description" : "Practice soccer skills and compete in inter-school matches" ,
44- "schedule" : "Mondays and Wednesdays, 4:00 PM - 5:30 PM" ,
45- "max_participants" : 22 ,
46- "participants" : ["liam@mergington.edu" , "noah@mergington.edu" ]
47- },
48- "Basketball Club" : {
49- "description" : "Develop teamwork and basketball fundamentals" ,
50- "schedule" : "Tuesdays and Fridays, 4:00 PM - 5:30 PM" ,
51- "max_participants" : 15 ,
52- "participants" : ["ava@mergington.edu" , "isabella@mergington.edu" ]
53- },
54- "Drama Club" : {
55- "description" : "Explore acting, stage presence, and theater production" ,
56- "schedule" : "Thursdays, 3:30 PM - 5:00 PM" ,
57- "max_participants" : 18 ,
58- "participants" : ["mia@mergington.edu" , "charlotte@mergington.edu" ]
59- },
60- "Painting Workshop" : {
61- "description" : "Learn painting techniques and create visual art projects" ,
62- "schedule" : "Wednesdays, 3:30 PM - 5:00 PM" ,
63- "max_participants" : 16 ,
64- "participants" : ["amelia@mergington.edu" , "harper@mergington.edu" ]
65- },
66- "Debate Team" : {
67- "description" : "Build public speaking and critical thinking through debates" ,
68- "schedule" : "Mondays, 3:30 PM - 5:00 PM" ,
69- "max_participants" : 14 ,
70- "participants" : ["elijah@mergington.edu" , "james@mergington.edu" ]
71- },
72- "Math Olympiad" : {
73- "description" : "Solve advanced math problems and prepare for competitions" ,
74- "schedule" : "Fridays, 3:30 PM - 5:00 PM" ,
75- "max_participants" : 12 ,
76- "participants" : ["lucas@mergington.edu" , "benjamin@mergington.edu" ]
77- }
24+ "Chess Club" : {
25+ "description" : "Learn strategies and compete in chess tournaments" ,
26+ "schedule" : "Fridays, 3:30 PM - 5:00 PM" ,
27+ "max_participants" : 12 ,
28+ "participants" : ["michael@mergington.edu" , "daniel@mergington.edu" ]
29+ },
30+ "Programming Class" : {
31+ "description" : "Learn programming fundamentals and build software projects" ,
32+ "schedule" : "Tuesdays and Thursdays, 3:30 PM - 4:30 PM" ,
33+ "max_participants" : 20 ,
34+ "participants" : ["emma@mergington.edu" , "sophia@mergington.edu" ]
35+ },
36+ "Gym Class" : {
37+ "description" : "Physical education and sports activities" ,
38+ "schedule" : "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM" ,
39+ "max_participants" : 30 ,
40+ "participants" : ["john@mergington.edu" , "olivia@mergington.edu" ]
41+ },
42+ "Soccer Team" : {
43+ "description" : "Practice soccer skills and compete in inter-school matches" ,
44+ "schedule" : "Mondays and Wednesdays, 4:00 PM - 5:30 PM" ,
45+ "max_participants" : 22 ,
46+ "participants" : ["liam@mergington.edu" , "noah@mergington.edu" ]
47+ },
48+ "Basketball Club" : {
49+ "description" : "Develop teamwork and basketball fundamentals" ,
50+ "schedule" : "Tuesdays and Fridays, 4:00 PM - 5:30 PM" ,
51+ "max_participants" : 15 ,
52+ "participants" : ["ava@mergington.edu" , "isabella@mergington.edu" ]
53+ },
54+ "Drama Club" : {
55+ "description" : "Explore acting, stage presence, and theater production" ,
56+ "schedule" : "Thursdays, 3:30 PM - 5:00 PM" ,
57+ "max_participants" : 18 ,
58+ "participants" : ["mia@mergington.edu" , "charlotte@mergington.edu" ]
59+ },
60+ "Painting Workshop" : {
61+ "description" : "Learn painting techniques and create visual art projects" ,
62+ "schedule" : "Wednesdays, 3:30 PM - 5:00 PM" ,
63+ "max_participants" : 16 ,
64+ "participants" : ["amelia@mergington.edu" , "harper@mergington.edu" ]
65+ },
66+ "Debate Team" : {
67+ "description" : "Build public speaking and critical thinking through debates" ,
68+ "schedule" : "Mondays, 3:30 PM - 5:00 PM" ,
69+ "max_participants" : 14 ,
70+ "participants" : ["elijah@mergington.edu" , "james@mergington.edu" ]
71+ },
72+ "Math Olympiad" : {
73+ "description" : "Solve advanced math problems and prepare for competitions" ,
74+ "schedule" : "Fridays, 3:30 PM - 5:00 PM" ,
75+ "max_participants" : 12 ,
76+ "participants" : ["lucas@mergington.edu" , "benjamin@mergington.edu" ]
77+ }
78+
7879}
7980
8081
@@ -88,20 +89,27 @@ def get_activities():
8889 return activities
8990
9091
92+
93+ # POST: Register participant
9194@app .post ("/activities/{activity_name}/signup" )
9295def signup_for_activity (activity_name : str , email : str ):
93- """Sign up a student for an activity"""
94- # Validate activity exists
95- if activity_name not in activities :
96- raise HTTPException (status_code = 404 , detail = "Activity not found" )
97-
98- # Get the specific activity
99- activity = activities [activity_name ]
100-
101- # Validate student is not already signed up
102- if email in activity ["participants" ]:
103- raise HTTPException (status_code = 400 , detail = "Student already signed up for this activity" )
96+ """Sign up a student for an activity"""
97+ if activity_name not in activities :
98+ raise HTTPException (status_code = 404 , detail = "Activity not found" )
99+ activity = activities [activity_name ]
100+ if email in activity ["participants" ]:
101+ raise HTTPException (status_code = 400 , detail = "Student already signed up for this activity" )
102+ activity ["participants" ].append (email )
103+ return {"message" : f"Signed up { email } for { activity_name } " }
104104
105- # Add student
106- activity ["participants" ].append (email )
107- return {"message" : f"Signed up { email } for { activity_name } " }
105+ # DELETE: Unregister participant
106+ @app .delete ("/activities/{activity_name}/signup" )
107+ def unregister_from_activity (activity_name : str , email : str ):
108+ """Remove a student from an activity"""
109+ if activity_name not in activities :
110+ raise HTTPException (status_code = 404 , detail = "Activity not found" )
111+ activity = activities [activity_name ]
112+ if email not in activity ["participants" ]:
113+ raise HTTPException (status_code = 404 , detail = "Student not registered for this activity" )
114+ activity ["participants" ].remove (email )
115+ return {"message" : f"Removed { email } from { activity_name } " }
0 commit comments