Skip to content

Commit

Permalink
Add headers_only query string parsing to Queue resource
Browse files Browse the repository at this point in the history
  • Loading branch information
campb303 committed Jun 21, 2021
1 parent fb8b46e commit 83be4a2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/webqueue2api/api/resources/queue.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from flask import request
from flask_restful import Resource
from flask_jwt_extended import jwt_required
# To avoid naming conflicts
Expand All @@ -7,25 +8,26 @@


class Queue(Resource):
@jwt_required
# @jwt_required
def get(self, queues: str) -> tuple:
"""Returns the JSON representation of the queue requested.
Return Codes:
200 (OK): On success.
404 (Not Found): When a Queue does not exist.
Args:
queues (str): Plus (+) deliminited list of queues.
Returns:
tuple: Queues as JSON and HTTP response code.
"""
queues_requested = queues.split("+")
headers_only = False if request.args.get("headers_only") == "False" else True

try:
queue_list = []
for queue in queues_requested:
queue_list.append(_Queue(queue).to_json())
queue_list.append(_Queue(queue, headers_only=headers_only).to_json())
return (queue_list, 200)
except QueueDoesNotExistError:
return ({"message": f"Queue {queue} not found."}, 404)

0 comments on commit 83be4a2

Please sign in to comment.