From 102feaadd3cc6d2e072d845852100513ca39029b Mon Sep 17 00:00:00 2001 From: hyh123a Date: Wed, 20 Apr 2022 15:58:43 +0800 Subject: [PATCH] add the ticket status api --- myems-api/app.py | 4 +- myems-api/reports/ticket.py | 87 ++++++++++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/myems-api/app.py b/myems-api/app.py index c8d18951..7e09aa1b 100644 --- a/myems-api/app.py +++ b/myems-api/app.py @@ -116,7 +116,6 @@ api.add_route('/ticket/apply/{id_}', api.add_route('/ticket/list/agent', ticket.TicketAgentListCollection()) - # Get Ticket List: My Relation api.add_route('/ticket/list/completed', ticket.TicketCompletedListCollection()) @@ -125,6 +124,9 @@ api.add_route('/ticket/list/completed', api.add_route('/ticket/list/intervention', ticket.TicketInterventionListCollection()) +# My Application: Get Ticket Status +api.add_route('/ticket/status/{id_}', + ticket.TicketStatusItem()) ######################################################################################################################## # Routes for System Core ######################################################################################################################## diff --git a/myems-api/reports/ticket.py b/myems-api/reports/ticket.py index a360f4b2..7dea36ad 100644 --- a/myems-api/reports/ticket.py +++ b/myems-api/reports/ticket.py @@ -7,8 +7,8 @@ import re from core.useractivity import user_logger, access_control import requests -# BASE_API = 'http://172.16.203.116/' -BASE_API = 'http://192.168.1.4/' +BASE_API = 'http://172.16.203.116/' +# BASE_API = 'http://192.168.1.4/' def login(): @@ -662,6 +662,89 @@ class TicketInterventionListCollection: resp.text = json.dumps(result) +class TicketStatusItem: + @staticmethod + def __init__(): + """"Initializes ContactCollection""" + pass + + @staticmethod + def on_options(req, resp, id_): + resp.status = falcon.HTTP_200 + + @staticmethod + def on_get(req, resp, id_): + if not id_.isdigit() or int(id_) <= 0: + raise falcon.HTTPError(falcon.HTTP_400, '400 Bad Request') + + ticket_id = int(id_) + session = login() + url = BASE_API + "/api/v1.0/tickets/"+id_+"/flowsteps" + headers = { + 'Content-Type': 'application/json', + } + get_resp = session.get(url, headers=headers) + content = json.loads(get_resp.text) + print("content", content) + resp.text = json.dumps(content) + + @staticmethod + def on_post(req, resp, id_): + """Handles POST requests""" + try: + raw_json = req.stream.read().decode('utf-8') + except Exception as ex: + raise falcon.HTTPError(falcon.HTTP_400, title='API.ERROR', description=ex) + """ + { + "title": "测试维修", + "long_field": "测试维修", + "transition_id": 29, + "workflow_id": 4 + }""" + print("id_", id_) + new_values = json.loads(raw_json) + + checked_fields = [ + { + "name": "transition_id", + "type": int + }, + { + "name": "workflow_id", + "type": int + }, + + ] + + 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 + + session = login() + url = BASE_API + "/api/v1.0/tickets" + headers = { + 'Content-Type': 'application/json', + } + resp = session.post(url, headers=headers, data=json.dumps(payload)) + content = json.loads(resp.text) + print("content", content) + new_ticket_id = content.get('ticket_id') + print(resp.status_code) + if resp.status_code != 200: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_COOKIE', + description='API.INVALID_STATUS_CODE:' + str(resp.status_code)) + resp.status = falcon.HTTP_201 + resp.location = '/tickets/' + str(new_ticket_id) + + class ContactItem: @staticmethod def __init__():