Skip to content

Commit 545fa9b

Browse files
authored
Merge pull request #2 from JorgeLuisOR/accelerate-with-copilot
Add registration validation and more activities
2 parents 342b6a9 + c94a955 commit 545fa9b

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
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": ["john@mergington.edu", "olivia@mergington.edu"]
41+
},
42+
# Sports related activities
43+
"Soccer Team": {
44+
"description": "Join the school soccer team and compete in local leagues",
45+
"schedule": "Tuesdays and Thursdays, 4:00 PM - 5:30 PM",
46+
"max_participants": 18,
47+
"participants": ["lucas@mergington.edu", "mia@mergington.edu"]
48+
},
49+
"Basketball Club": {
50+
"description": "Practice basketball skills and play friendly matches",
51+
"schedule": "Wednesdays, 3:30 PM - 5:00 PM",
52+
"max_participants": 15,
53+
"participants": ["liam@mergington.edu", "ava@mergington.edu"]
54+
},
55+
# Artistic activities
56+
"Drama Club": {
57+
"description": "Participate in school plays and improve acting skills",
58+
"schedule": "Mondays, 4:00 PM - 5:30 PM",
59+
"max_participants": 20,
60+
"participants": ["noah@mergington.edu", "isabella@mergington.edu"]
61+
},
62+
"Art Workshop": {
63+
"description": "Explore painting, drawing, and other visual arts",
64+
"schedule": "Fridays, 2:00 PM - 3:30 PM",
65+
"max_participants": 16,
66+
"participants": ["amelia@mergington.edu", "benjamin@mergington.edu"]
67+
},
68+
# Intellectual activities
69+
"Math Olympiad": {
70+
"description": "Prepare for math competitions and solve challenging problems",
71+
"schedule": "Thursdays, 3:30 PM - 5:00 PM",
72+
"max_participants": 10,
73+
"participants": ["charlotte@mergington.edu", "elijah@mergington.edu"]
74+
},
75+
"Debate Team": {
76+
"description": "Develop public speaking and argumentation skills",
77+
"schedule": "Wednesdays, 4:00 PM - 5:30 PM",
78+
"max_participants": 14,
79+
"participants": ["harper@mergington.edu", "jackson@mergington.edu"]
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 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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,19 @@ document.addEventListener("DOMContentLoaded", () => {
2222

2323
activityCard.innerHTML = `
2424
<h4>${name}</h4>
25-
<p>${details.description}</p>
25+
<p><strong>Description:</strong> ${details.description}</p>
2626
<p><strong>Schedule:</strong> ${details.schedule}</p>
2727
<p><strong>Availability:</strong> ${spotsLeft} spots left</p>
28+
<div class="participants-section">
29+
<strong>Participants:</strong>
30+
${
31+
details.participants && details.participants.length > 0
32+
? `<ul class="participants-list">
33+
${details.participants.map(email => `<li>${email}</li>`).join('')}
34+
</ul>`
35+
: `<span class="no-participants">No participants yet.</span>`
36+
}
37+
</div>
2838
`;
2939

3040
activitiesList.appendChild(activityCard);

src/static/index.html

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,51 @@ <h3>Sign Up for an Activity</h3>
4545
<p>&copy; 2023 Mergington High School</p>
4646
</footer>
4747

48-
<script src="app.js"></script>
48+
<script>
49+
// Fetch and render activities
50+
async function loadActivities() {
51+
const activitiesList = document.getElementById('activities-list');
52+
const activitySelect = document.getElementById('activity');
53+
activitiesList.innerHTML = '<p>Loading activities...</p>';
54+
try {
55+
const res = await fetch('/activities');
56+
const activities = await res.json();
57+
activitiesList.innerHTML = '';
58+
activitySelect.innerHTML = '<option value="">-- Select an activity --</option>';
59+
Object.entries(activities).forEach(([name, info]) => {
60+
// Create activity card
61+
const card = document.createElement('div');
62+
card.className = 'activity-card';
63+
card.innerHTML = `
64+
<h4>${name}</h4>
65+
<p><strong>Description:</strong> ${info.description}</p>
66+
<p><strong>Schedule:</strong> ${info.schedule}</p>
67+
<p><strong>Max Participants:</strong> ${info.max_participants}</p>
68+
<div class="participants-section">
69+
<strong>Participants:</strong>
70+
${
71+
info.participants && info.participants.length > 0
72+
? `<ul class="participants-list">
73+
${info.participants.map(email => `<li>${email}</li>`).join('')}
74+
</ul>`
75+
: `<span class="no-participants">No participants yet.</span>`
76+
}
77+
</div>
78+
`;
79+
activitiesList.appendChild(card);
80+
81+
// Add to select
82+
const option = document.createElement('option');
83+
option.value = name;
84+
option.textContent = name;
85+
activitySelect.appendChild(option);
86+
});
87+
} catch (err) {
88+
activitiesList.innerHTML = '<p class="error">Failed to load activities.</p>';
89+
}
90+
}
91+
92+
window.addEventListener('DOMContentLoaded', loadActivities);
93+
</script>
4994
</body>
5095
</html>

src/static/styles.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,30 @@ footer {
142142
padding: 20px;
143143
color: #666;
144144
}
145+
146+
.participants-section {
147+
margin-top: 12px;
148+
padding: 10px;
149+
background: #eef3fb;
150+
border-radius: 4px;
151+
border: 1px solid #c5cae9;
152+
}
153+
154+
.participants-section strong {
155+
color: #3949ab;
156+
display: block;
157+
margin-bottom: 6px;
158+
}
159+
160+
.participants-list {
161+
margin-left: 18px;
162+
margin-bottom: 0;
163+
color: #283593;
164+
font-size: 0.97em;
165+
}
166+
167+
.no-participants {
168+
color: #888;
169+
font-style: italic;
170+
margin-left: 4px;
171+
}

0 commit comments

Comments
 (0)