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
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"args": [
"src.app:app",
"--reload",
"--reload-include",
"src/static/*"
"--reload-include=src/static/*"
],
"jinja": true
}
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
fastapi
uvicorn
httpx
watchfiles
watchfiles
pytest
40 changes: 40 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 Team": {
"description": "Join the school's basketball team and compete in local leagues",
"schedule": "Tuesdays and Thursdays, 4:00 PM - 6:00 PM",
"max_participants": 15,
"participants": ["liam@mergington.edu"]
},
"Soccer Club": {
"description": "Practice soccer skills and play friendly matches",
"schedule": "Wednesdays, 3:30 PM - 5:30 PM",
"max_participants": 18,
"participants": ["noah@mergington.edu"]
},
"Art Club": {
"description": "Explore painting, drawing, and other visual arts",
"schedule": "Mondays, 3:30 PM - 5:00 PM",
"max_participants": 15,
"participants": ["ava@mergington.edu"]
},
"Drama Society": {
"description": "Participate in theater productions and acting workshops",
"schedule": "Fridays, 4:00 PM - 6:00 PM",
"max_participants": 20,
"participants": ["mia@mergington.edu"]
},
"Math Olympiad": {
"description": "Prepare for math competitions and solve challenging problems",
"schedule": "Thursdays, 3:30 PM - 5:00 PM",
"max_participants": 10,
"participants": ["william@mergington.edu"]
},
"Debate Club": {
"description": "Develop public speaking and argumentation skills",
"schedule": "Wednesdays, 4:00 PM - 5:30 PM",
"max_participants": 16,
"participants": ["charlotte@mergington.edu"]
}
}

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

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

# Add student
activity["participants"].append(email)
return {"message": f"Signed up {email} for {activity_name}"}
20 changes: 20 additions & 0 deletions src/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,31 @@ document.addEventListener("DOMContentLoaded", () => {

const spotsLeft = details.max_participants - details.participants.length;

// Create participants list HTML
let participantsHTML = "";
if (details.participants && details.participants.length > 0) {
participantsHTML = `
<div class="participants-section">
<strong>Participants:</strong>
<ul class="participants-list">
${details.participants.map(p => `<li>${p}</li>`).join("")}
</ul>
</div>
`;
} else {
participantsHTML = `
<div class="participants-section empty">
<em>No participants yet</em>
</div>
`;
}

activityCard.innerHTML = `
<h4>${name}</h4>
<p>${details.description}</p>
<p><strong>Schedule:</strong> ${details.schedule}</p>
<p><strong>Availability:</strong> ${spotsLeft} spots left</p>
${participantsHTML}
`;

activitiesList.appendChild(activityCard);
Expand Down
25 changes: 25 additions & 0 deletions src/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,31 @@ section h3 {
margin-bottom: 8px;
}

.participants-section {
margin-top: 10px;
padding: 10px;
background-color: #eef3fa;
border-radius: 4px;
border: 1px solid #c5cae9;
}
.participants-section strong {
color: #3949ab;
font-size: 15px;
}
.participants-list {
margin: 8px 0 0 18px;
padding-left: 0;
list-style-type: disc;
color: #333;
font-size: 15px;
}
.participants-section.empty {
background-color: #f9f9f9;
color: #888;
border: 1px dashed #ccc;
font-style: italic;
}

.form-group {
margin-bottom: 15px;
}
Expand Down
Empty file added tests/__init__.py
Empty file.
67 changes: 67 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import pytest
from fastapi.testclient import TestClient
from src.app import app, activities

client = TestClient(app)

# Helper to reset activities for test isolation
def reset_participants():
for activity in activities.values():
if isinstance(activity.get("participants"), list):
activity["participants"] = []

def test_get_activities():
# Arrange
reset_participants()
# Act
response = client.get("/activities")
# Assert
assert response.status_code == 200
data = response.json()
assert isinstance(data, dict)
assert "Chess Club" in data

def test_signup_for_activity():
# Arrange
reset_participants()
email = "testuser@mergington.edu"
# Act
response = client.post(f"/activities/Chess Club/signup?email={email}")
# Assert
assert response.status_code == 200
assert email in activities["Chess Club"]["participants"]


def test_signup_duplicate():
# Arrange
reset_participants()
email = "testuser@mergington.edu"
client.post(f"/activities/Chess Club/signup?email={email}")
# Act
response = client.post(f"/activities/Chess Club/signup?email={email}")
# Assert
assert response.status_code == 400
assert response.json()["detail"] == "Student is already signed up for this activity"


def test_unregister_participant():
# Arrange
reset_participants()
email = "testuser@mergington.edu"
client.post(f"/activities/Chess Club/signup?email={email}")
# Act
response = client.delete(f"/activities/Chess Club/unregister?email={email}")
# Assert
assert response.status_code == 200
assert email not in activities["Chess Club"]["participants"]


def test_unregister_nonexistent():
# Arrange
reset_participants()
email = "notfound@mergington.edu"
# Act
response = client.delete(f"/activities/Chess Club/unregister?email={email}")
# Assert
assert response.status_code == 404
assert response.json()["detail"] == "Participant not found in this activity"
Loading