Skip to content

Commit 661ed8d

Browse files
committed
temp
1 parent b7b0da4 commit 661ed8d

File tree

7 files changed

+200
-3
lines changed

7 files changed

+200
-3
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.aws-sam/
2+
venv/
23
__pycache__

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

code/mapper.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from student.upload import get_upload_url
22
from recruiter.get import get_resume_url
3+
from code.student.user import get_user, update_user, register_user
34
import json
45
import traceback
56

@@ -57,12 +58,58 @@ def getResumeUrl(context, queryParams):
5758
traceback.print_exc()
5859
return rval
5960

61+
def getUser(context, queryParams):
62+
rval = {}
63+
if not 'uid' in queryParams:
64+
return badRequest("Query parameter 'uid' is missing.")
65+
try:
66+
user: str = get_user(queryParams['uid'])
67+
rval = {
68+
"statusCode": 200,
69+
"body": json.dumps({
70+
"user": user
71+
})
72+
}
73+
except:
74+
rval = serverError("Could not get user.")
75+
traceback.print_exc()
76+
return rval
77+
78+
def updateUser(context, queryParams):
79+
rval = {}
80+
if not 'uid' in queryParams:
81+
return badRequest("Query parameter 'uid' is missing.")
82+
try:
83+
update_user(queryParams['uid'])
84+
except:
85+
rval = serverError("Could not get user.")
86+
traceback.print_exc()
87+
return rval
88+
89+
def registerUser(context, queryParams):
90+
rval = {}
91+
if not 'uid' in queryParams:
92+
return badRequest("Query parameter 'uid' is missing.")
93+
try:
94+
register_user(queryParams['uid'])
95+
except:
96+
rval = serverError("Could not get user.")
97+
traceback.print_exc()
98+
return rval
99+
60100
find_handler = {
61101
"GET": {
62102
"/api/v1/healthz": healthzHandler,
63103
"/api/v1/student/getUploadURL": getUploadUrl,
64104
"/api/v1/recruiter/getResumeUrl": getResumeUrl,
65105
"/api/v1/recruiter/getResumeListings": notImplemented,
106+
"/api/v1/student": getUser
107+
},
108+
"PUT": {
109+
"/api/v1/student": updateUser
110+
},
111+
"POST": {
112+
"/api/v1/student": registerUser
66113
}
67114
}
68115

code/student/user.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import boto3, os
2+
3+
class Student:
4+
uid: int
5+
name: str
6+
email: str
7+
linkedin: str
8+
degree: int
9+
majors: list
10+
minors: list
11+
gpa: float
12+
year: str
13+
bio: str
14+
skills: list
15+
position: int
16+
work_auth: bool
17+
sponsor: bool
18+
19+
def __init__(self, uid, name, email, linkedin, degree, majors, minors, gpa, year, bio, skills, position, work_auth, sponsor):
20+
self.uid: uid
21+
self.name: name
22+
self.email: email
23+
self.linkedin: linkedin
24+
self.degree: degree
25+
self.majors: majors
26+
self.minors: minors
27+
self.gpa: gpa
28+
self.year: year
29+
self.bio: bio
30+
self.skills: skills
31+
self.position: position
32+
self.work_auth: work_auth
33+
self.sponsor: sponsor
34+
35+
client = boto3.client('dynamodb', region_name=os.environ.get('AWS_REGION', 'us-east-2'))
36+
dynamo_table = 'infra-resume-book-users'
37+
38+
def get_user(uid: int) -> str | None:
39+
response = client.get_item(
40+
TableName=dynamo_table,
41+
Key={
42+
'uid': uid
43+
}
44+
)
45+
46+
def update_user(uid, name = None, email = None, linkedin = None, degree = None, majors = None, minors = None, gpa = None, year = None, bio = None, skills = None, position = None, work_auth = None, sponsor = None):
47+
response = client.update_item(
48+
TableName=dynamo_table,
49+
Key={
50+
'uid': uid
51+
},
52+
UpdateExpression='SET #n = :n, #e = :e, #l = :l, #d = :d, #ma = list_append(#ma, :ma), #mi = list_append(#mi, :mi), #g = :g, #y = :y, #b = :b, #sk = list_append(#sk, :sk), #p = :p, #sp = :sp',
53+
ExpressionAttributeNames={
54+
'#n': "name",
55+
'#e': "email",
56+
'#l': "linkedin",
57+
'#d': "degree",
58+
'#ma': "majors",
59+
'#mi': "minors",
60+
'#g': "gpa",
61+
'#y': "year",
62+
'#b': "bio",
63+
'#sk': "skills",
64+
'#p': "position",
65+
'#sp': "sponsor"
66+
},
67+
ExpressionAttributeValues={
68+
':n': {'S': name},
69+
':e': {'S': email},
70+
':l': {'S': linkedin},
71+
':d': {'N': degree},
72+
':ma': {'SS': majors},
73+
':mi': {'SS': minors},
74+
':g': {'N': gpa},
75+
':y': {'S': year},
76+
':b': {'S': bio},
77+
':sk': {'SS': skills},
78+
':p': {'N': position},
79+
':w': {'BOOL': work_auth},
80+
':ma': {'BOOL': sponsor},
81+
}
82+
)
83+
84+
def register_user(uid, name, email, linkedin, degree, majors, minors, gpa, year, bio, skills, position, work_auth, sponsor):
85+
client.put_item(
86+
TableName=dynamo_table,
87+
Item={
88+
"uid": {'N': uid},
89+
"name": {'S': name},
90+
"email": {'S': email},
91+
"linkedin": {'S': linkedin},
92+
"degree": {'N': degree},
93+
"majors": {'SS': majors},
94+
"minors": {'SS': minors},
95+
"gpa": {'N': gpa},
96+
"year": {'S': year},
97+
"bio": {'S': bio},
98+
"skills": {'SS': skills},
99+
"position": {'N': position},
100+
"work_auth": {'BOOL': work_auth},
101+
"sponsor": {'BOOL': sponsor}
102+
}
103+
)

create_table.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import boto3
2+
3+
def create_devices_table(dynamodb=None):
4+
dynamodb = boto3.resource(
5+
'dynamodb', region_name='us-east-2')
6+
table = dynamodb.create_table(
7+
TableName='infra-resume-book-users',
8+
KeySchema=[
9+
{
10+
'AttributeName': 'uin',
11+
'KeyType': 'HASH' # Partition key
12+
}
13+
],
14+
AttributeDefinitions=[
15+
{
16+
'AttributeName': 'uin',
17+
'AttributeType': 'N'
18+
}
19+
],
20+
ProvisionedThroughput={
21+
'ReadCapacityUnits': 10,
22+
'WriteCapacityUnits': 10
23+
}
24+
)
25+
return table
26+
27+
28+
if __name__ == '__main__':
29+
device_table = create_devices_table()
30+
# Print tablle status
31+
print("Status:", device_table.table_status)

test.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"resource": "/myresource",
3+
"path": "/api/v1/healthz",
4+
"httpMethod": "GET",
5+
"headers": {
6+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
7+
"Accept-Encoding": "gzip, deflate, sdch",
8+
"Accept-Language": "en-US,en;q=0.8"
9+
},
10+
"queryStringParameters": {
11+
"param1": "value1",
12+
"param2": "value2"
13+
},
14+
"pathParameters": null,
15+
"stageVariables": null,
16+
"requestContext": {},
17+
"body": "request body goes here"
18+
}

0 commit comments

Comments
 (0)