-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandler.py
More file actions
48 lines (36 loc) · 1.04 KB
/
Copy pathhandler.py
File metadata and controls
48 lines (36 loc) · 1.04 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
import json
import boto3
import os
import uuid
dynamodb = boto3.resource('dynamodb', region_name='us-west-2')
def add_approve(event, context):
data = json.loads(event['body'])
tableApprove = dynamodb.Table(os.environ['TABLE_APPROVE'])
tableMain = dynamodb.Table(os.environ['TABLE_MAIN'])
item = {
'id': str(uuid.uuid4()),
'uoId': data['uoId'],
'numHours': data['numHours'],
'date': data['date'],
'proctor': data['proctor']
}
checkId = tableMain.get_item(
Key={
'uoId': data['uoId']
}
)
item['name'] = checkId['Item']['fname'] + " " + checkId['Item']['lname']
response = {
'headers': {
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Credentials' : True
}
}
if 'Item' in checkId:
tableApprove.put_item(Item=item)
response['statusCode'] = 200
response['body'] = "goodId"
else:
response['statusCode'] = 400
response['body'] = "badId"
return response