add the ticket status api

pull/141/head
hyh123a 2022-04-20 15:58:43 +08:00
parent 276be1c988
commit 102feaadd3
2 changed files with 88 additions and 3 deletions

View File

@ -116,7 +116,6 @@ api.add_route('/ticket/apply/{id_}',
api.add_route('/ticket/list/agent', api.add_route('/ticket/list/agent',
ticket.TicketAgentListCollection()) ticket.TicketAgentListCollection())
# Get Ticket List: My Relation # Get Ticket List: My Relation
api.add_route('/ticket/list/completed', api.add_route('/ticket/list/completed',
ticket.TicketCompletedListCollection()) ticket.TicketCompletedListCollection())
@ -125,6 +124,9 @@ api.add_route('/ticket/list/completed',
api.add_route('/ticket/list/intervention', api.add_route('/ticket/list/intervention',
ticket.TicketInterventionListCollection()) ticket.TicketInterventionListCollection())
# My Application: Get Ticket Status
api.add_route('/ticket/status/{id_}',
ticket.TicketStatusItem())
######################################################################################################################## ########################################################################################################################
# Routes for System Core # Routes for System Core
######################################################################################################################## ########################################################################################################################

View File

@ -7,8 +7,8 @@ import re
from core.useractivity import user_logger, access_control from core.useractivity import user_logger, access_control
import requests import requests
# BASE_API = 'http://172.16.203.116/' BASE_API = 'http://172.16.203.116/'
BASE_API = 'http://192.168.1.4/' # BASE_API = 'http://192.168.1.4/'
def login(): def login():
@ -662,6 +662,89 @@ class TicketInterventionListCollection:
resp.text = json.dumps(result) 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: class ContactItem:
@staticmethod @staticmethod
def __init__(): def __init__():