mirror of
https://github.com/jlengrand/getting-started-with-github-copilot.git
synced 2026-03-10 08:21:18 +00:00
Add extracurricular activities and signup validation to the API
This commit is contained in:
45
src/app.py
45
src/app.py
@@ -38,6 +38,45 @@ activities = {
|
|||||||
"schedule": "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM",
|
"schedule": "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM",
|
||||||
"max_participants": 30,
|
"max_participants": 30,
|
||||||
"participants": ["john@mergington.edu", "olivia@mergington.edu"]
|
"participants": ["john@mergington.edu", "olivia@mergington.edu"]
|
||||||
|
},
|
||||||
|
# Sports related activities
|
||||||
|
"Soccer Team": {
|
||||||
|
"description": "Join the school soccer team and compete in matches",
|
||||||
|
"schedule": "Wednesdays, 4:00 PM - 5:30 PM",
|
||||||
|
"max_participants": 18,
|
||||||
|
"participants": ["lucas@mergington.edu", "mia@mergington.edu"]
|
||||||
|
},
|
||||||
|
"Basketball Club": {
|
||||||
|
"description": "Practice basketball skills and play friendly games",
|
||||||
|
"schedule": "Thursdays, 3:30 PM - 5:00 PM",
|
||||||
|
"max_participants": 15,
|
||||||
|
"participants": ["liam@mergington.edu", "ava@mergington.edu"]
|
||||||
|
},
|
||||||
|
# Artistic activities
|
||||||
|
"Art Workshop": {
|
||||||
|
"description": "Explore painting, drawing, and sculpture techniques",
|
||||||
|
"schedule": "Mondays, 4:00 PM - 5:30 PM",
|
||||||
|
"max_participants": 16,
|
||||||
|
"participants": ["ella@mergington.edu", "noah@mergington.edu"]
|
||||||
|
},
|
||||||
|
"Drama Club": {
|
||||||
|
"description": "Act, direct, and produce school plays and performances",
|
||||||
|
"schedule": "Tuesdays, 3:30 PM - 5:00 PM",
|
||||||
|
"max_participants": 20,
|
||||||
|
"participants": ["isabella@mergington.edu", "jack@mergington.edu"]
|
||||||
|
},
|
||||||
|
# Intellectual activities
|
||||||
|
"Mathletes": {
|
||||||
|
"description": "Compete in math competitions and solve challenging problems",
|
||||||
|
"schedule": "Fridays, 4:00 PM - 5:00 PM",
|
||||||
|
"max_participants": 10,
|
||||||
|
"participants": ["oliver@mergington.edu", "charlotte@mergington.edu"]
|
||||||
|
},
|
||||||
|
"Science Club": {
|
||||||
|
"description": "Conduct experiments and explore scientific concepts",
|
||||||
|
"schedule": "Wednesdays, 3:30 PM - 5:00 PM",
|
||||||
|
"max_participants": 14,
|
||||||
|
"participants": ["henry@mergington.edu", "amelia@mergington.edu"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +94,12 @@ def get_activities():
|
|||||||
@app.post("/activities/{activity_name}/signup")
|
@app.post("/activities/{activity_name}/signup")
|
||||||
def signup_for_activity(activity_name: str, email: str):
|
def signup_for_activity(activity_name: str, email: str):
|
||||||
"""Sign up a student for an activity"""
|
"""Sign up a student for an activity"""
|
||||||
|
|
||||||
|
# Validate student is not already signed up
|
||||||
|
for activity in activities.values():
|
||||||
|
if email in activity["participants"]:
|
||||||
|
raise HTTPException(status_code=400, detail="Student already signed up for an activity")
|
||||||
|
|
||||||
# Validate activity exists
|
# Validate activity exists
|
||||||
if activity_name not in activities:
|
if activity_name not in activities:
|
||||||
raise HTTPException(status_code=404, detail="Activity not found")
|
raise HTTPException(status_code=404, detail="Activity not found")
|
||||||
|
|||||||
Reference in New Issue
Block a user