generated from skills/getting-started-with-github-copilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Improve student activity registration system #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| fastapi | ||
| pytest | ||
| httpx | ||
| uvicorn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,45 @@ | |
| "schedule": "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM", | ||
| "max_participants": 30, | ||
| "participants": ["[email protected]", "[email protected]"] | ||
| }, | ||
| # Sports related activities | ||
| "Soccer Team": { | ||
| "description": "Join the school soccer team and compete in local matches", | ||
| "schedule": "Wednesdays, 4:00 PM - 5:30 PM", | ||
| "max_participants": 18, | ||
| "participants": ["[email protected]", "[email protected]"] | ||
| }, | ||
| "Basketball Club": { | ||
| "description": "Practice basketball skills and play friendly games", | ||
| "schedule": "Mondays, 3:30 PM - 5:00 PM", | ||
| "max_participants": 15, | ||
| "participants": ["[email protected]", "[email protected]"] | ||
| }, | ||
| # Artistic activities | ||
| "Art Workshop": { | ||
| "description": "Explore painting, drawing, and sculpture techniques", | ||
| "schedule": "Thursdays, 4:00 PM - 5:30 PM", | ||
| "max_participants": 16, | ||
| "participants": ["[email protected]", "[email protected]"] | ||
| }, | ||
| "Drama Club": { | ||
| "description": "Act, direct, and produce school plays and performances", | ||
| "schedule": "Tuesdays, 3:30 PM - 5:00 PM", | ||
| "max_participants": 20, | ||
| "participants": ["[email protected]", "[email protected]"] | ||
| }, | ||
| # Intellectual activities | ||
| "Math Olympiad": { | ||
| "description": "Prepare for math competitions and solve challenging problems", | ||
| "schedule": "Fridays, 4:00 PM - 5:30 PM", | ||
| "max_participants": 10, | ||
| "participants": ["[email protected]", "[email protected]"] | ||
| }, | ||
| "Science Club": { | ||
| "description": "Conduct experiments and explore scientific concepts", | ||
| "schedule": "Wednesdays, 3:30 PM - 5:00 PM", | ||
| "max_participants": 14, | ||
| "participants": ["[email protected]", "[email protected]"] | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -62,6 +101,25 @@ 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}"} | ||
|
|
||
|
|
||
| # Unregister a participant from an activity | ||
| from fastapi import Query | ||
|
||
|
|
||
| @app.delete("/activities/{activity_name}/unregister") | ||
| def unregister_from_activity(activity_name: str, email: str = Query(...)): | ||
| """Remove a participant 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=400, detail="Participant not found in this activity") | ||
| activity["participants"].remove(email) | ||
| return {"message": f"Unregistered {email} from {activity_name}"} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import pytest | ||
| from fastapi.testclient import TestClient | ||
| from src.app import app | ||
|
|
||
| client = TestClient(app) | ||
|
|
||
| # Test GET /activities | ||
| def test_get_activities(): | ||
| response = client.get("/activities") | ||
| assert response.status_code == 200 | ||
| data = response.json() | ||
| assert "Chess Club" in data | ||
| assert "Programming Class" in data | ||
| assert "Gym Class" in data | ||
|
|
||
| # Test POST /activities/{activity_name}/signup | ||
| @pytest.mark.parametrize("activity,email", [ | ||
| ("Chess Club", "[email protected]"), | ||
| ("Programming Class", "[email protected]"), | ||
| ]) | ||
| def test_signup_for_activity(activity, email): | ||
| response = client.post(f"/activities/{activity}/signup?email={email}") | ||
| assert response.status_code == 200 | ||
| assert f"Signed up {email} for {activity}" in response.json()["message"] | ||
|
|
||
| # Test duplicate signup | ||
| def test_duplicate_signup(): | ||
| activity = "Chess Club" | ||
| email = "[email protected]" | ||
| response = client.post(f"/activities/{activity}/signup?email={email}") | ||
| assert response.status_code == 400 | ||
| assert "already signed up" in response.json()["detail"] | ||
|
|
||
| # Test DELETE /activities/{activity_name}/unregister | ||
| @pytest.mark.parametrize("activity,email", [ | ||
| ("Chess Club", "[email protected]"), | ||
| ("Programming Class", "[email protected]"), | ||
| ]) | ||
| def test_unregister_from_activity(activity, email): | ||
| response = client.delete(f"/activities/{activity}/unregister?email={email}") | ||
| assert response.status_code == 200 | ||
| assert f"Unregistered {email} from {activity}" in response.json()["message"] | ||
|
|
||
| # Test unregister non-existent participant | ||
| def test_unregister_nonexistent(): | ||
| activity = "Chess Club" | ||
| email = "[email protected]" | ||
| response = client.delete(f"/activities/{activity}/unregister?email={email}") | ||
| assert response.status_code == 400 | ||
| assert "Participant not found" in response.json()["detail"] | ||
|
|
||
| # Test activity not found | ||
| @pytest.mark.parametrize("endpoint", [ | ||
| "/activities/Unknown/[email protected]", | ||
| "/activities/Unknown/[email protected]", | ||
| ]) | ||
| def test_activity_not_found(endpoint): | ||
| method = "post" if "signup" in endpoint else "delete" | ||
| response = getattr(client, method)(endpoint) | ||
| assert response.status_code == 404 | ||
| assert "Activity not found" in response.json()["detail"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment has incorrect indentation - it should align with the code it describes rather than being outdented to column 0.