From 20b0c37eb99ccc1dc00b974d72e710fb50254b8f Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Fri, 30 Oct 2020 11:42:08 -0400 Subject: [PATCH] Move getQueues endpoint to get_queues --- api/api.py | 119 ++++++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 55 deletions(-) diff --git a/api/api.py b/api/api.py index 2f10f1b..f77e7fc 100644 --- a/api/api.py +++ b/api/api.py @@ -11,72 +11,81 @@ class Item(Resource): - def get(self, queue: str, number: int) -> str: - """Returns the JSON representation of the item requested. - - Example: - /api/ce/100 returns: - { - "lastUpdated": "07-23-20 10:11 PM", - "headers": [...], - "content": [...], - "isLocked": "ce 100 is locked by knewell using qvi", - "userEmail": "campb303@purdue.edu", - "userName": "Justin Campbell", - "userAlias": "campb303", - "assignedTo": "campb303", - "subject": "Beepboop", - "status": "Dont Delete", - "priority": "", - "deparment": "", - "building": "", - "dateReceived": "Tue, 23 Jun 2020 13:25:51 -0400" - } - - Args: - queue (str): The queue of the item requested. - item (int): The number of the item requested. - - Returns: - str: JSON representation of the item requested. - """ - return ECNQueue.Item(queue, number).toJson() + def get(self, queue: str, number: int) -> str: + """Returns the JSON representation of the item requested. + + Example: + /api/ce/100 returns: + { + "lastUpdated": "07-23-20 10:11 PM", + "headers": [...], + "content": [...], + "isLocked": "ce 100 is locked by knewell using qvi", + "userEmail": "campb303@purdue.edu", + "userName": "Justin Campbell", + "userAlias": "campb303", + "assignedTo": "campb303", + "subject": "Beepboop", + "status": "Dont Delete", + "priority": "", + "deparment": "", + "building": "", + "dateReceived": "Tue, 23 Jun 2020 13:25:51 -0400" + } + + Args: + queue (str): The queue of the item requested. + item (int): The number of the item requested. + + Returns: + str: JSON representation of the item requested. + """ + return ECNQueue.Item(queue, number).toJson() class Queue(Resource): - def get(self, queue: str) -> str: - """Returns the JSON representation of the queue requested. + def get(self, queue: str) -> str: + """Returns the JSON representation of the queue requested. - Args: - queue (str): The queue requested. + Args: + queue (str): The queue requested. - Returns: - str: JSON representation of the queue requested. - """ - queues_requested = queue.split("+") + Returns: + str: JSON representation of the queue requested. + """ + queues_requested = queue.split("+") - queues = [] - for queue in queues_requested: - queues.append(ECNQueue.Queue(queue).toJson()) + queues = [] + for queue in queues_requested: + queues.append(ECNQueue.Queue(queue).toJson()) - return queues + return queues class QueueList(Resource): - def get(self) -> list: - """Returns a list of queues and the number of items in the queue - - Example: - [example] - - Returns: - list: [description] - """ - return ECNQueue.getItemCount() - -api.add_resource(QueueList, "/api/getQueues") + def get(self) -> list: + """Returns a list of dictionaries with the number of items in each queue. + + Example: + [ + { + name: "me", + number_of_items: 42 + }, + { + name: "bidc", + number_of_items: 3 + } + ] + + Returns: + list: Dictionaries with the number of items in each queue. + """ + return ECNQueue.getQueueCounts() + +api.add_resource(QueueList, "/api/get_queues") api.add_resource(Item, "/api//") api.add_resource(Queue, "/api/") if __name__ == "__main__": - app.run() + app.run()