Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
fastapi
uvicorn
pytest
httpx
59 changes: 59 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@
"schedule": "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM",
"max_participants": 30,
"participants": ["john@mergington.edu", "olivia@mergington.edu"]
},
"Basketball": {
"description": "Team sport focusing on basketball skills and competitive play",
"schedule": "Mondays and Wednesdays, 4:00 PM - 5:30 PM",
"max_participants": 15,
"participants": ["alex@mergington.edu"]
},
"Tennis Club": {
"description": "Learn tennis techniques and participate in matches",
"schedule": "Saturdays, 10:00 AM - 11:30 AM",
"max_participants": 10,
"participants": ["james@mergington.edu"]
},
"Drama Club": {
"description": "Perform in theatrical productions and develop acting skills",
"schedule": "Wednesdays and Thursdays, 4:00 PM - 5:30 PM",
"max_participants": 25,
"participants": ["isabella@mergington.edu", "lucas@mergington.edu"]
},
"Art Studio": {
"description": "Create visual art including painting, drawing, and sculpture",
"schedule": "Tuesdays and Fridays, 3:30 PM - 5:00 PM",
"max_participants": 18,
"participants": ["sophie@mergington.edu"]
},
"Debate Team": {
"description": "Develop public speaking and argumentation skills",
"schedule": "Mondays and Thursdays, 3:30 PM - 4:45 PM",
"max_participants": 16,
"participants": ["noah@mergington.edu", "ava@mergington.edu"]
},
"Science Club": {
"description": "Explore scientific concepts through experiments and projects",
"schedule": "Wednesdays, 3:30 PM - 5:00 PM",
"max_participants": 20,
"participants": ["ethan@mergington.edu"]
}
}

Expand All @@ -62,6 +98,29 @@ def signup_for_activity(activity_name: str, email: str):
# Get the specific activity
activity = activities[activity_name]

# Validate student is not already signed up
if email in activity["participants"]:
raise HTTPException(status_code=400, detail="Student already signed up for this activity")

# Add student
activity["participants"].append(email)
return {"message": f"Signed up {email} for {activity_name}"}


@app.delete("/activities/{activity_name}/participants/{email}")
def remove_participant(activity_name: str, email: str):
"""Remove a participant from an activity"""
# Validate activity exists
if activity_name not in activities:
raise HTTPException(status_code=404, detail="Activity not found")

# Get the specific activity
activity = activities[activity_name]

# Validate student is signed up
if email not in activity["participants"]:
raise HTTPException(status_code=400, detail="Student is not signed up for this activity")

# Remove student
activity["participants"].remove(email)
return {"message": f"Removed {email} from {activity_name}"}
55 changes: 55 additions & 0 deletions src/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ document.addEventListener("DOMContentLoaded", () => {
<p>${details.description}</p>
<p><strong>Schedule:</strong> ${details.schedule}</p>
<p><strong>Availability:</strong> ${spotsLeft} spots left</p>
<div class="participants">
<h5>Participants (${details.participants.length})</h5>
<ul>
${details.participants.map(participant => `
<li>
<span>${participant}</span>
<button class="delete-btn" data-activity="${name}" data-email="${participant}" title="Remove participant">🗑️</button>
</li>
`).join('')}
</ul>
</div>
`;

activitiesList.appendChild(activityCard);
Expand Down Expand Up @@ -62,6 +73,8 @@ document.addEventListener("DOMContentLoaded", () => {
messageDiv.textContent = result.message;
messageDiv.className = "success";
signupForm.reset();
// Reload activities to show the new participant
fetchActivities();
} else {
messageDiv.textContent = result.detail || "An error occurred";
messageDiv.className = "error";
Expand All @@ -81,6 +94,48 @@ document.addEventListener("DOMContentLoaded", () => {
}
});

// Handle delete button clicks
activitiesList.addEventListener("click", async (event) => {
if (event.target.classList.contains("delete-btn")) {
const button = event.target;
const activity = button.getAttribute("data-activity");
const email = button.getAttribute("data-email");

try {
const response = await fetch(
`/activities/${encodeURIComponent(activity)}/participants/${encodeURIComponent(email)}`,
{
method: "DELETE",
}
);

const result = await response.json();

if (response.ok) {
messageDiv.textContent = result.message;
messageDiv.className = "success";
// Reload activities
fetchActivities();
} else {
messageDiv.textContent = result.detail || "Failed to remove participant";
messageDiv.className = "error";
}

messageDiv.classList.remove("hidden");

// Hide message after 5 seconds
setTimeout(() => {
messageDiv.classList.add("hidden");
}, 5000);
} catch (error) {
messageDiv.textContent = "Failed to remove participant. Please try again.";
messageDiv.className = "error";
messageDiv.classList.remove("hidden");
console.error("Error removing participant:", error);
}
}
});

// Initialize app
fetchActivities();
});
46 changes: 46 additions & 0 deletions src/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,52 @@ section h3 {
margin-bottom: 8px;
}

.activity-card .participants {
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid #e0e0e0;
}

.activity-card .participants h5 {
margin-bottom: 10px;
color: #1a237e;
font-size: 14px;
font-weight: bold;
}

.activity-card .participants ul {
margin-left: 0;
list-style-type: none;
}

.activity-card .participants li {
margin-bottom: 6px;
color: #555;
font-size: 14px;
display: flex;
align-items: center;
justify-content: space-between;
}

.activity-card .participants li span {
flex: 1;
}

.delete-btn {
background-color: transparent;
border: none;
font-size: 18px;
cursor: pointer;
padding: 4px 8px;
margin-left: 10px;
transition: transform 0.2s;
}

.delete-btn:hover {
background-color: transparent;
transform: scale(1.2);
}

.form-group {
margin-bottom: 15px;
}
Expand Down
Empty file added tests/__init__.py
Empty file.
Loading