Skip to content

Commit

Permalink
add getResumeUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
devksingh4 committed Jul 20, 2023
1 parent baf637a commit 53ebe24
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
5 changes: 3 additions & 2 deletions code/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
def lambda_handler(event, context):
method = event['httpMethod']
path = event['path']
queryParams = event["queryStringParameters"]
print(f"INFO: Processing request: method {method}, path {path}.")
try:
return mapper.execute(method, path, event['requestContext']['authorizer'])
return mapper.execute(method, path, queryParams, event['requestContext']['authorizer'])
except KeyError:
return mapper.execute(method, path, {})
return mapper.execute(method, path, queryParams, {})
45 changes: 33 additions & 12 deletions code/mapper.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from student.upload import get_upload_url
from recruiter.get import get_resume_url
import json
def healthzHandler(context):
import traceback

def healthzHandler(context, queryParams):
return {
"statusCode": 200,
"body": "UP"
}
def notImplemented(context):
def notImplemented(context, queryParams):
return {
"statusCode": 404,
"body": "Method not implemented."
Expand All @@ -15,7 +18,12 @@ def serverError(message):
"statusCode": 500,
"body": f"An error occurred - {message}"
}
def getUploadUrl(context):
def badRequest(message):
return {
"statusCode": 400,
"body": f"Bad request - {message}"
}
def getUploadUrl(context, queryParams):
rval = {}
try:
url: str = get_upload_url(f"resume_{context['uid']}.pdf")
Expand All @@ -25,27 +33,40 @@ def getUploadUrl(context):
"url": url
})
}
except Exception as e:
except:
rval = serverError("Could not create S3 upload URL.")
traceback.print_exc()
return rval


def getResumeUrl(context, queryParams):
rval = {}
if not 'uid' in queryParams:
return badRequest("Query parameter 'uid' is missing.")
try:
url: str = get_resume_url(queryParams['uid'])
rval = {
"statusCode": 200,
"body": json.dumps({
"url": url
})
}
except:
rval = serverError("Could not create S3 download URL.")
traceback.print_exc()
return rval

find_handler = {
"GET": {
"/api/v1/healthz": healthzHandler,
"/api/v1/student/getUploadURL": getUploadUrl,
"/api/v1/recruiter/getResumeListings": notImplemented,
"/api/v1/recruiter/getResumeUrl": getResumeUrl,
}
}

def execute(method: str, path: str, context: dict) -> dict:
def execute(method: str, path: str, queryParams: dict, context: dict) -> dict:
try:
func: function = find_handler[method][path]
return func(context)
return func(context, queryParams)
except KeyError as e:
print(f"ERROR: No handler found for method {method} and path {path}.")
return {
"statusCode": 404,
"body": f"No handler found for method {method} path {path}."
}
return notImplemented(context, queryParams)
12 changes: 12 additions & 0 deletions code/recruiter/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import boto3, os
s3 = boto3.client('s3', region_name=os.environ.get("AWS_REGION", "us-east-1"))
def get_resume_url(uid: str) -> str:
filename = f'resume_{uid}.pdf'
return s3.generate_presigned_url(
ClientMethod="get_object",
Params={
"Bucket": 'infra-resume-book-pdfs',
"Key": filename
},
ExpiresIn=3600
)

0 comments on commit 53ebe24

Please sign in to comment.