Skip to content

Commit

Permalink
Create Queue resource with error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
campb303 committed Jun 17, 2021
1 parent daf5b98 commit 1469b01
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/webqueue2api/api/resources/queue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from flask_restful import Resource
from flask_jwt_extended import jwt_required
# To avoid naming conflicts
from webqueue2api.parser import Queue as _Queue
from webqueue2api.parser.errors import QueueDoesNotExistError



class Queue(Resource):
# @jwt_required
def get(self, queues: str) -> tuple:
"""Returns the JSON representation of the queue requested.
Return Codes:
200 (OK): On success.
Args:
queues (str): Plus (+) deliminited list of queues.
Returns:
tuple: Queues as JSON and HTTP response code.
"""
queues_requested = queues.split("+")

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

0 comments on commit 1469b01

Please sign in to comment.