38
38
"schedule" : "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM" ,
39
39
"max_participants" : 30 ,
40
40
41
+ },
42
+ "Soccer Team" : {
43
+ "description" : "Join the school soccer team and compete in matches" ,
44
+ "schedule" : "Tuesdays and Thursdays, 4:00 PM - 6:00 PM" ,
45
+ "max_participants" : 22 ,
46
+
47
+ },
48
+ "Basketball Team" : {
49
+ "description" : "Practice basketball and participate in tournaments" ,
50
+ "schedule" : "Wednesdays and Fridays, 3:30 PM - 5:30 PM" ,
51
+ "max_participants" : 15 ,
52
+
53
+ },
54
+ "Art Club" : {
55
+ "description" : "Explore various art techniques and create masterpieces" ,
56
+ "schedule" : "Mondays, 3:30 PM - 5:00 PM" ,
57
+ "max_participants" : 15 ,
58
+
59
+ },
60
+ "Drama Club" : {
61
+ "description" : "Act, direct, and produce plays and performances" ,
62
+ "schedule" : "Thursdays, 4:00 PM - 5:30 PM" ,
63
+ "max_participants" : 20 ,
64
+
65
+ },
66
+ "Math Club" : {
67
+ "description" : "Solve challenging math problems and prepare for competitions" ,
68
+ "schedule" : "Wednesdays, 3:30 PM - 4:30 PM" ,
69
+ "max_participants" : 10 ,
70
+
71
+ },
72
+ "Science Club" : {
73
+ "description" : "Conduct experiments and explore scientific concepts" ,
74
+ "schedule" : "Fridays, 4:00 PM - 5:30 PM" ,
75
+ "max_participants" : 12 ,
76
+
41
77
}
42
78
}
43
79
44
-
45
80
@app .get ("/" )
46
81
def root ():
47
82
return RedirectResponse (url = "/static/index.html" )
@@ -53,6 +88,7 @@ def get_activities():
53
88
54
89
55
90
@app .post ("/activities/{activity_name}/signup" )
91
+
56
92
def signup_for_activity (activity_name : str , email : str ):
57
93
"""Sign up a student for an activity"""
58
94
# Validate activity exists
@@ -63,5 +99,12 @@ def signup_for_activity(activity_name: str, email: str):
63
99
activity = activities [activity_name ]
64
100
65
101
# Add student
102
+ # Validate student is not already signed up
103
+ if email in activity ["participants" ]:
104
+ raise HTTPException (status_code = 400 , detail = "Already signed up" )
105
+ # Validate max participants
106
+ if len (activity ["participants" ]) >= activity ["max_participants" ]:
107
+ raise HTTPException (status_code = 400 , detail = "Activity is full" )
108
+ # Add student to the activity
66
109
activity ["participants" ].append (email )
67
110
return {"message" : f"Signed up { email } for { activity_name } " }
0 commit comments