From ac263817479c620343baf09806c779c3a4e20b5d Mon Sep 17 00:00:00 2001 From: hyh123a Date: Sun, 17 Apr 2022 14:39:08 +0800 Subject: [PATCH] add the list api --- myems-api/app.py | 5 ++- myems-api/reports/ticket.py | 61 ++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/myems-api/app.py b/myems-api/app.py index 9557af8f..a5c04075 100644 --- a/myems-api/app.py +++ b/myems-api/app.py @@ -101,9 +101,12 @@ cors = CORS(allow_all_origins=True, api = falcon.App(middleware=[cors.middleware, MultipartMiddleware()]) +# Get Ticket Type api.add_route('/ticket/types', ticket.TicketTypeCollection()) - +# Get Ticket List +api.add_route('/ticket/list', + ticket.TicketListCollection()) ######################################################################################################################## # Routes for System Core ######################################################################################################################## diff --git a/myems-api/reports/ticket.py b/myems-api/reports/ticket.py index c9b4a712..32716f14 100644 --- a/myems-api/reports/ticket.py +++ b/myems-api/reports/ticket.py @@ -22,10 +22,9 @@ class TicketTypeCollection: cnx = mysql.connector.connect(**config.loonflow) cursor = cnx.cursor() - query = (" SELECT id, name, uuid, " - " email, phone, description " - " FROM tbl_contacts " - " ORDER BY name ") + query = (" SELECT id, name, description, display_form_str " + " FROM workflow_workflow " + " ORDER BY id ") cursor.execute(query) rows = cursor.fetchall() cursor.close() @@ -36,15 +35,61 @@ class TicketTypeCollection: for row in rows: meta_result = {"id": row[0], "name": row[1], - "uuid": row[2], - "email": row[3], - "phone": row[4], - "description": row[5]} + "description": row[2], + "display_form_str": row[3]} result.append(meta_result) resp.text = json.dumps(result) +class TicketListCollection: + @staticmethod + def __init__(): + """"Initializes ContactCollection""" + pass + @staticmethod + def on_options(req, resp): + resp.status = falcon.HTTP_200 + + @staticmethod + def on_get(req, resp): + cnx = mysql.connector.connect(**config.loonflow) + cursor = cnx.cursor() + + query = (" SELECT id, name " + " FROM workflow_workflow " + " ORDER BY id ") + cursor.execute(query) + workflow_rows = cursor.fetchall() + + workflow_result = {} + if workflow_rows is not None and len(workflow_rows) > 0: + for row in workflow_rows: + workflow_result[row[0]] = row[1] + + query = (" SELECT id, title, workflow_id, sn, state_id, creator, gmt_created, gmt_modified " + " FROM ticketed_ticketrecord " + " ORDER BY id ") + cursor.execute(query) + rows = cursor.fetchall() + cursor.close() + cnx.close() + + result = list() + if rows is not None and len(rows) > 0: + for row in rows: + meta_result = {"id": row[0], + "title": row[1], + "workflow_name": workflow_result.get(row[2]), + "sn": row[3], + "state_id": row[4], + "creator": row[5], + "gmt_created": row[6], + "gmt_modified": row[7] + } + result.append(meta_result) + + resp.text = json.dumps(result) class ContactItem: @staticmethod