Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if query params are none #82

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/lambdas/api/episode_by_id/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,26 @@ def handle(event, context):
item_id = event["pathParameters"].get("item_id")
query_params = event.get("queryStringParameters")

api_name = None
if query_params is not None:
api_name = query_params.get("api_name")

if collection_name not in schema.COLLECTION_NAMES:
return {"statusCode": 400, "body": json.dumps({"message": f"Invalid collection name, allowed values: {schema.COLLECTION_NAMES}"})}

if method == "GET":
return _get_episode(username, collection_name, item_id,
episode_id, auth_header, query_params)
episode_id, auth_header, api_name)
elif method == "PUT":
body = event.get("body")
return _put_episode(username, collection_name, item_id, episode_id,
body, auth_header, query_params)
body, auth_header, api_name)
elif method == "DELETE":
return _delete_episode(username, collection_name, item_id, episode_id,
auth_header, query_params)
auth_header, api_name)


def _get_episode(username, collection_name, item_id, episode_id, token, query_params):
api_name = query_params.get("api_name")
def _get_episode(username, collection_name, item_id, episode_id, token, api_name):
s_ret = None
try:
if collection_name == "anime":
Expand All @@ -73,8 +76,7 @@ def _get_episode(username, collection_name, item_id, episode_id, token, query_pa
return {"statusCode": 404}


def _put_episode(username, collection_name, item_id, episode_id, body, token, query_params):
api_name = query_params.get("api_name")
def _put_episode(username, collection_name, item_id, episode_id, body, token, api_name):
try:
body = json.loads(body)
except (TypeError, JSONDecodeError):
Expand Down Expand Up @@ -129,8 +131,7 @@ def _put_episode(username, collection_name, item_id, episode_id, body, token, qu
return {"statusCode": 204}


def _delete_episode(username, collection_name, item_id, episode_id, token, query_params):
api_name = query_params.get("api_name")
def _delete_episode(username, collection_name, item_id, episode_id, token, api_name):
res = None
try:
if collection_name == "anime":
Expand Down