Skip to content

Commit ca8d5e3

Browse files
committed
Add extracurricular activities and signup validation to the API
1 parent 73cd0db commit ca8d5e3

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/app.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +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+
# Sports activities
43+
"Soccer Team": {
44+
"description": "Team soccer practice and inter-school matches",
45+
"schedule": "Mondays, Wednesdays, 4:00 PM - 6:00 PM",
46+
"max_participants": 22,
47+
"participants": ["[email protected]", "[email protected]"]
48+
},
49+
"Basketball Team": {
50+
"description": "Competitive basketball team training and games",
51+
"schedule": "Tuesdays, Thursdays, 4:00 PM - 6:00 PM",
52+
"max_participants": 15,
53+
"participants": ["[email protected]", "[email protected]"]
54+
},
55+
# Artistic activities
56+
"Art Club": {
57+
"description": "Explore drawing, painting, and mixed media projects",
58+
"schedule": "Wednesdays, 3:30 PM - 5:00 PM",
59+
"max_participants": 18,
60+
"participants": ["[email protected]", "[email protected]"]
61+
},
62+
"Drama Club": {
63+
"description": "Acting, stagecraft, and producing school plays",
64+
"schedule": "Fridays, 4:00 PM - 6:00 PM",
65+
"max_participants": 25,
66+
"participants": ["[email protected]", "[email protected]"]
67+
},
68+
# Intellectual activities
69+
"Debate Club": {
70+
"description": "Develop public speaking, argumentation, and research skills",
71+
"schedule": "Thursdays, 3:30 PM - 5:00 PM",
72+
"max_participants": 20,
73+
"participants": ["[email protected]", "[email protected]"]
74+
},
75+
"Robotics Club": {
76+
"description": "Build and program robots for challenges and competitions",
77+
"schedule": "Tuesdays, Fridays, 3:30 PM - 5:30 PM",
78+
"max_participants": 16,
79+
"participants": ["[email protected]", "[email protected]"]
4180
}
4281
}
4382

@@ -62,6 +101,10 @@ def signup_for_activity(activity_name: str, email: str):
62101
# Get the specific activity
63102
activity = activities[activity_name]
64103

104+
# Validate student is not already signed up
105+
if email in activity["participants"]:
106+
raise HTTPException(status_code=400, detail="Student is already signed up")
107+
65108
# Add student
66109
activity["participants"].append(email)
67110
return {"message": f"Signed up {email} for {activity_name}"}

src/static/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ document.addEventListener("DOMContentLoaded", () => {
1313
// Clear loading message
1414
activitiesList.innerHTML = "";
1515

16+
// Reset activity select options to the default
17+
activitySelect.innerHTML = "<option value=''>Select an activity</option>";
18+
1619
// Populate activities list
1720
Object.entries(activities).forEach(([name, details]) => {
1821
const activityCard = document.createElement("div");
@@ -62,6 +65,9 @@ document.addEventListener("DOMContentLoaded", () => {
6265
messageDiv.textContent = result.message;
6366
messageDiv.className = "success";
6467
signupForm.reset();
68+
69+
// Refresh activities so the UI reflects the new participant and prevents duplicate attempts
70+
fetchActivities();
6571
} else {
6672
messageDiv.textContent = result.detail || "An error occurred";
6773
messageDiv.className = "error";

0 commit comments

Comments
 (0)