From b9b0264837b707814e696182dcd45f04f1c35534 Mon Sep 17 00:00:00 2001 From: hyh123a Date: Mon, 18 Apr 2022 21:40:02 +0800 Subject: [PATCH] modify the ticket agent list api --- myems-api/app.py | 2 +- myems-api/reports/ticket.py | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/myems-api/app.py b/myems-api/app.py index 859d8b16..a06fa334 100644 --- a/myems-api/app.py +++ b/myems-api/app.py @@ -113,7 +113,7 @@ api.add_route('/ticket/apply/{id_}', ticket.TicketApplicationCollection()) # Get Ticket List: My Agent -api.add_route('/ticket/agent/list', +api.add_route('/ticket/list/agent', ticket.TicketAgentListCollection()) ######################################################################################################################## # Routes for System Core diff --git a/myems-api/reports/ticket.py b/myems-api/reports/ticket.py index fdcd5588..55937474 100644 --- a/myems-api/reports/ticket.py +++ b/myems-api/reports/ticket.py @@ -304,7 +304,37 @@ class TicketAgentListCollection: resp.status = falcon.HTTP_200 @staticmethod - def on_get(req, resp): + def on_post(req, resp): + + try: + raw_json = req.stream.read().decode('utf-8') + except Exception as ex: + raise falcon.HTTPError(falcon.HTTP_400, title='API.ERROR', description=ex) + """ + { + "user_name": "admin", + }""" + new_values = json.loads(raw_json) + + checked_fields = [ + { + "name": "user_name", + "type": str + }, + ] + + for field in checked_fields: + _name = field['name'] + _type = field['type'] + if _name not in new_values.keys() or \ + not isinstance(new_values[_name], _type) or \ + len(str(new_values[_name])) == 0: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.INVALID_FIELD' + _name) + + payload = new_values + user_name = payload['user_name'] + cnx = mysql.connector.connect(**config.loonflow) cursor = cnx.cursor() @@ -332,8 +362,9 @@ class TicketAgentListCollection: query = (" SELECT id, title, workflow_id, sn, state_id, creator, gmt_created, gmt_modified " " FROM ticket_ticketrecord " - " ORDER BY id DESC") - cursor.execute(query) + " WHERE participant = %s " + " ORDER BY id DESC ") + cursor.execute(query, (user_name, )) rows = cursor.fetchall() cursor.close() cnx.close()