-
Notifications
You must be signed in to change notification settings - Fork 0
/
join_event.py
48 lines (42 loc) · 1.37 KB
/
join_event.py
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
# join_event.py
import falcon
import json
from constants import *
from events import get_event_data, get_people
class JoinEvent(object):
def on_post(
self,
req: falcon.Request,
resp: falcon.Response,
event_id: str,
person_id: str
):
'''
Add a person to an event.
HTTP response codes:
200 if successful
404 if event doesn't exist
403 if event is at its max occupancy
'''
event_data = get_event_data(event_id)
if event_data == {}:
resp.status = falcon.HTTP_404
elif 'maxOccupancy' in event_data and (
len(get_people(event_id)) >= int(event_data['maxOccupancy'])
):
resp.status = falcon.HTTP_403
resp.content_type = 'text/html'
resp.body = '''
<html>
<head>
<title>Forbidden</title>
</head>
<body>
<h1><p>The requested event has reached its maximum occupancy.</p></h1>
</body>
</html>
'''
else:
conn.sadd(event_id + ':people', person_id)
conn.sadd('person:' + person_id, event_id)
resp.status = falcon.HTTP_200