-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
108 lines (95 loc) · 3.88 KB
/
app.py
File metadata and controls
108 lines (95 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
High School Management System API
A super simple FastAPI application that allows students to view and sign up
for extracurricular activities at Mergington High School.
"""
from fastapi import FastAPI, HTTPException
from fastapi.staticfiles import StaticFiles
from fastapi.responses import RedirectResponse
import os
from pathlib import Path
app = FastAPI(title="Mergington High School API",
description="API for viewing and signing up for extracurricular activities")
# Mount the static files directory
current_dir = Path(__file__).parent
app.mount("/static", StaticFiles(directory=os.path.join(Path(__file__).parent,
"static")), name="static")
# In-memory activity database
activities = {
"Chess Club": {
"description": "Learn strategies and compete in chess tournaments",
"schedule": "Fridays, 3:30 PM - 5:00 PM",
"max_participants": 12,
"participants": ["michael@mergington.edu", "daniel@mergington.edu"]
},
"Programming Class": {
"description": "Learn programming fundamentals and build software projects",
"schedule": "Tuesdays and Thursdays, 3:30 PM - 4:30 PM",
"max_participants": 20,
"participants": ["emma@mergington.edu", "sophia@mergington.edu"]
},
"Gym Class": {
"description": "Physical education and sports activities",
"schedule": "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM",
"max_participants": 30,
"participants": ["john@mergington.edu", "olivia@mergington.edu"]
},
# Sports related activities
"Soccer Team": {
"description": "Join the school soccer team and compete in local leagues",
"schedule": "Tuesdays and Thursdays, 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 matches",
"schedule": "Wednesdays, 3:30 PM - 5:00 PM",
"max_participants": 15,
"participants": ["liam@mergington.edu", "ava@mergington.edu"]
},
# Artistic activities
"Art Club": {
"description": "Explore painting, drawing, and other visual arts",
"schedule": "Mondays, 3:30 PM - 5:00 PM",
"max_participants": 16,
"participants": ["ella@mergington.edu", "noah@mergington.edu"]
},
"Drama Society": {
"description": "Participate in theater productions and acting workshops",
"schedule": "Fridays, 4:00 PM - 6:00 PM",
"max_participants": 20,
"participants": ["amelia@mergington.edu", "jack@mergington.edu"]
},
# Intellectual activities
"Math Olympiad": {
"description": "Prepare for math competitions and solve challenging problems",
"schedule": "Thursdays, 3:30 PM - 5:00 PM",
"max_participants": 14,
"participants": ["charlotte@mergington.edu", "benjamin@mergington.edu"]
},
"Debate Club": {
"description": "Develop public speaking and argumentation skills",
"schedule": "Wednesdays, 4:00 PM - 5:30 PM",
"max_participants": 12,
"participants": ["henry@mergington.edu", "grace@mergington.edu"]
}
}
@app.get("/")
def root():
return RedirectResponse(url="/static/index.html")
@app.get("/activities")
def get_activities():
return activities
@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"]:
# Add student
activity["participants"].append(email)
return {"message": f"Signed up {email} for {activity_name}"}