Skip to content

Improve student activity registration system - #2

Merged
mpcs2013 merged 3 commits into
mainfrom
accelerate-with-copilot
Mar 26, 2026
Merged

mpcs2013 merged 3 commits into
mainfrom
accelerate-with-copilot

Conversation

@mpcs2013

Copy link
Copy Markdown
Owner

This pull request adds the ability for students to unregister from activities, improves the user interface for managing participants, and introduces automated tests to ensure the correctness of the core features. It also expands the list of available activities and enhances the overall user experience with better feedback and styling.

Backend API enhancements:

  • Added a new DELETE endpoint (/activities/{activity_name}/participants?email=...) to allow students to unregister from an activity, with appropriate error handling for missing activities or participants. [1] [2]
  • Updated the signup logic to prevent duplicate signups by checking if a student is already registered for an activity.

Frontend improvements:

  • Modified the activities list to display current participants for each activity, including a "Remove" button next to each participant for easy unregistration.
  • Added client-side logic to call the new unregister API when a participant is removed, and to refresh the activities list after changes.
  • Improved feedback to users by centralizing message display logic and ensuring messages are shown for both signup and removal actions.

Styling and UI enhancements:

  • Enhanced the visual design of activity cards and the participants section, including new styles for participant lists and delete buttons, for a more user-friendly and modern appearance.

Testing:

  • Introduced a comprehensive test suite (tests/test_app.py) covering activity listing, signup, duplicate signup prevention, unregistration, and error cases, ensuring API reliability and correctness.

Data model update:

  • Added several new activities (e.g., Basketball Team, Tennis Club, Art Studio, Drama Club, Debate Team, Science Club) with sample participants to the in-memory data model.

@mpcs2013
mpcs2013 requested a review from Copilot March 26, 2026 12:25
@mpcs2013
mpcs2013 marked this pull request as draft March 26, 2026 12:27
@mpcs2013
mpcs2013 marked this pull request as ready for review March 26, 2026 12:27
@mpcs2013
mpcs2013 merged commit 5aa7098 into main Mar 26, 2026
6 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the Mergington High School activities app to support unregistering participants, improves the activities UI to show/manage participant lists, and adds an automated API test suite to cover the core flows.

Changes:

  • Added a DELETE /activities/{activity_name}/participants?email=... API to unregister students, and prevented duplicate signups.
  • Updated the frontend to render per-activity participant lists with a remove button and centralized message display logic.
  • Added pytest coverage for listing, signup, duplicate signup prevention, unregister, and error cases; updated styling and dependencies.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/app.py Adds new activities, blocks duplicate signups, and introduces the unregister endpoint.
src/static/app.js Renders participant lists, wires up “Remove” (DELETE) calls, refreshes the UI, and centralizes message handling.
src/static/styles.css Adds participant list and delete button styling; updates activity card styling.
tests/test_app.py Introduces API-level tests for redirect, listing, signup, duplicates, unregister, and not-found cases.
src/README.md Documents the new DELETE endpoint.
requirements.txt Adds pytest and fixes formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app.py
Comment on lines 91 to +122
@app.post("/activities/{activity_name}/signup")
def signup_for_activity(activity_name: str, email: str):
"""Sign up a student for 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 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")
def unregister_from_activity(activity_name: str, email: str):
"""Remove a student from an activity"""
if activity_name not in activities:
raise HTTPException(status_code=404, detail="Activity not found")

activity = activities[activity_name]

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

activity["participants"].remove(email)
return {"message": f"Removed {email} from {activity_name}"}

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The email query parameter is accepted as a free-form str for both signup and unregister. Since it’s later rendered in the UI, it’s safer to validate/normalize it at the API boundary (e.g., EmailStr, strip(), and consistent casing) to reduce the chance of storing unexpected values and to provide consistent duplicate detection/unregister behavior.

Copilot uses AI. Check for mistakes.
Comment thread src/static/app.js
Comment on lines +38 to 70
const participantItems = details.participants.length
? details.participants
.map(
(participant) => `
<li class="participant-item">
<span class="participant-email">${participant}</span>
<button
type="button"
class="participant-delete"
data-activity="${name}"
data-email="${participant}"
aria-label="Remove ${participant} from ${name}"
title="Unregister participant"
>
<span aria-hidden="true">×</span>
</button>
</li>
`
)
.join("")
: '<li class="participants-empty">No one has signed up yet.</li>';

activityCard.innerHTML = `
<h4>${name}</h4>
<p>${details.description}</p>
<p><strong>Schedule:</strong> ${details.schedule}</p>
<p><strong>Availability:</strong> ${spotsLeft} spots left</p>
<div class="participants-section">
<p class="participants-title">Current Participants</p>
<ul class="participants-list">${participantItems}</ul>
</div>
`;

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Participant emails are inserted into the DOM via template literals assigned to innerHTML (both text nodes and data-* attributes). Since email is user-controlled (signup query param), this enables XSS/HTML injection and can also break the data-email attribute if the value contains quotes. Prefer building the participant list with DOM APIs (createElement, textContent, dataset) or escaping/sanitizing values before interpolating into HTML.

Suggested change
const participantItems = details.participants.length
? details.participants
.map(
(participant) => `
<li class="participant-item">
<span class="participant-email">${participant}</span>
<button
type="button"
class="participant-delete"
data-activity="${name}"
data-email="${participant}"
aria-label="Remove ${participant} from ${name}"
title="Unregister participant"
>
<span aria-hidden="true">×</span>
</button>
</li>
`
)
.join("")
: '<li class="participants-empty">No one has signed up yet.</li>';
activityCard.innerHTML = `
<h4>${name}</h4>
<p>${details.description}</p>
<p><strong>Schedule:</strong> ${details.schedule}</p>
<p><strong>Availability:</strong> ${spotsLeft} spots left</p>
<div class="participants-section">
<p class="participants-title">Current Participants</p>
<ul class="participants-list">${participantItems}</ul>
</div>
`;
// Build static structure for the activity card without interpolating untrusted data into HTML
activityCard.innerHTML = `
<h4 class="activity-name"></h4>
<p class="activity-description"></p>
<p class="activity-schedule"><strong>Schedule:</strong> <span class="activity-schedule-value"></span></p>
<p class="activity-availability"><strong>Availability:</strong> <span class="activity-spots-left"></span> spots left</p>
<div class="participants-section">
<p class="participants-title">Current Participants</p>
<ul class="participants-list"></ul>
</div>
`;
// Populate static fields using textContent to avoid HTML injection
const nameEl = activityCard.querySelector(".activity-name");
const descriptionEl = activityCard.querySelector(".activity-description");
const scheduleValueEl = activityCard.querySelector(".activity-schedule-value");
const spotsLeftEl = activityCard.querySelector(".activity-spots-left");
const participantsListEl = activityCard.querySelector(".participants-list");
if (nameEl) {
nameEl.textContent = name;
}
if (descriptionEl) {
descriptionEl.textContent = details.description;
}
if (scheduleValueEl) {
scheduleValueEl.textContent = details.schedule;
}
if (spotsLeftEl) {
spotsLeftEl.textContent = String(spotsLeft);
}
// Populate participants list safely using DOM APIs
if (details.participants.length && participantsListEl) {
details.participants.forEach((participant) => {
const li = document.createElement("li");
li.className = "participant-item";
const emailSpan = document.createElement("span");
emailSpan.className = "participant-email";
emailSpan.textContent = participant;
const deleteButton = document.createElement("button");
deleteButton.type = "button";
deleteButton.className = "participant-delete";
deleteButton.dataset.activity = name;
deleteButton.dataset.email = participant;
deleteButton.setAttribute("aria-label", `Remove ${participant} from ${name}`);
deleteButton.title = "Unregister participant";
const innerSpan = document.createElement("span");
innerSpan.setAttribute("aria-hidden", "true");
innerSpan.textContent = "×";
deleteButton.appendChild(innerSpan);
li.appendChild(emailSpan);
li.appendChild(deleteButton);
participantsListEl.appendChild(li);
});
} else if (participantsListEl) {
const emptyLi = document.createElement("li");
emptyLi.className = "participants-empty";
emptyLi.textContent = "No one has signed up yet.";
participantsListEl.appendChild(emptyLi);
}

Copilot uses AI. Check for mistakes.
Comment thread src/static/app.js

function showMessage(message, type) {
messageDiv.textContent = message;
messageDiv.className = type;

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showMessage() assigns messageDiv.className = type, which overwrites any existing/base classes on the message element (e.g., a shared "message" class for padding/margins) and can make styling brittle. Consider using classList to toggle status classes while preserving a stable base class.

Suggested change
messageDiv.className = type;
// Remove any previous status classes while preserving base classes
messageDiv.classList.remove("error", "success");
if (type) {
messageDiv.classList.add(type);
}

Copilot uses AI. Check for mistakes.
Comment thread src/static/app.js
Comment on lines 6 to +13

function showMessage(message, type) {
messageDiv.textContent = message;
messageDiv.className = type;
messageDiv.classList.remove("hidden");

setTimeout(() => {
messageDiv.classList.add("hidden");

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showMessage() creates a new setTimeout each time it’s called without clearing any prior timer. If multiple messages are shown quickly, an earlier timeout can hide the latest message prematurely. Track the timeout id and clearTimeout() before scheduling a new hide.

Suggested change
function showMessage(message, type) {
messageDiv.textContent = message;
messageDiv.className = type;
messageDiv.classList.remove("hidden");
setTimeout(() => {
messageDiv.classList.add("hidden");
let messageTimeoutId;
function showMessage(message, type) {
messageDiv.textContent = message;
messageDiv.className = type;
messageDiv.classList.remove("hidden");
if (messageTimeoutId) {
clearTimeout(messageTimeoutId);
}
messageTimeoutId = setTimeout(() => {
messageDiv.classList.add("hidden");
messageTimeoutId = undefined;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants