Skip to content

Commit c0e02f1

Browse files
Add new activities and signup validation to app
1 parent 4e66110 commit c0e02f1

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

src/app.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,45 @@
3838
"schedule": "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM",
3939
"max_participants": 30,
4040
"participants": ["[email protected]", "[email protected]"]
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+
"participants": ["[email protected]", "[email protected]"]
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+
"participants": ["[email protected]", "[email protected]"]
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+
"participants": ["[email protected]", "[email protected]"]
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+
"participants": ["[email protected]", "[email protected]"]
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+
"participants": ["[email protected]", "[email protected]"]
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+
"participants": ["[email protected]", "[email protected]"]
4177
}
4278
}
4379

44-
4580
@app.get("/")
4681
def root():
4782
return RedirectResponse(url="/static/index.html")
@@ -53,6 +88,7 @@ def get_activities():
5388

5489

5590
@app.post("/activities/{activity_name}/signup")
91+
5692
def signup_for_activity(activity_name: str, email: str):
5793
"""Sign up a student for an activity"""
5894
# Validate activity exists
@@ -63,5 +99,12 @@ def signup_for_activity(activity_name: str, email: str):
6399
activity = activities[activity_name]
64100

65101
# 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
66109
activity["participants"].append(email)
67110
return {"message": f"Signed up {email} for {activity_name}"}

0 commit comments

Comments
 (0)