add the ticket apply post api
parent
6d0c298923
commit
f5dc197172
|
@ -111,6 +111,7 @@ api.add_route('/ticket/list',
|
||||||
# Apply One Ticket
|
# Apply One Ticket
|
||||||
api.add_route('/ticket/apply/{id_}',
|
api.add_route('/ticket/apply/{id_}',
|
||||||
ticket.TicketApplicationCollection())
|
ticket.TicketApplicationCollection())
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
# Routes for System Core
|
# Routes for System Core
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
|
@ -5,6 +5,28 @@ import config
|
||||||
import uuid
|
import uuid
|
||||||
import re
|
import re
|
||||||
from core.useractivity import user_logger, access_control
|
from core.useractivity import user_logger, access_control
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def login():
|
||||||
|
url = "http://192.168.1.4/api/v1.0/login"
|
||||||
|
|
||||||
|
payload = json.dumps({
|
||||||
|
"username": "admin",
|
||||||
|
"password": "123456",
|
||||||
|
"type": "account"
|
||||||
|
})
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
session = requests.session()
|
||||||
|
response = session.post(url, headers=headers, data=payload)
|
||||||
|
status = response.status_code
|
||||||
|
|
||||||
|
if status == 200:
|
||||||
|
return session
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class TicketTypeCollection:
|
class TicketTypeCollection:
|
||||||
|
@ -193,6 +215,68 @@ class TicketApplicationCollection:
|
||||||
|
|
||||||
resp.text = json.dumps(result)
|
resp.text = json.dumps(result)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def on_post(req, resp, id_):
|
||||||
|
"""Handles POST requests"""
|
||||||
|
access_control(req)
|
||||||
|
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
|
||||||
|
}"""
|
||||||
|
new_values = json.loads(raw_json)
|
||||||
|
|
||||||
|
checked_fields = [
|
||||||
|
{
|
||||||
|
"name": "title",
|
||||||
|
"type": str
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "long_field",
|
||||||
|
"type": str
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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['data'].keys() or \
|
||||||
|
not isinstance(new_values['data'][_name], _type) or \
|
||||||
|
len(str.strip(new_values['data'][_name])) == 0:
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_FIELD' + _name)
|
||||||
|
|
||||||
|
payload = new_values['data']
|
||||||
|
|
||||||
|
session = login()
|
||||||
|
url = 'http://192.168.1.4/api/v1.0/tickets'
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
resp = session.post(url, headers=headers, data=payload)
|
||||||
|
content = json.loads(resp.text)
|
||||||
|
new_ticket_id = content['data']['ticket_id']
|
||||||
|
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
|
||||||
|
@ -394,4 +478,3 @@ class ContactItem:
|
||||||
cnx.close()
|
cnx.close()
|
||||||
|
|
||||||
resp.status = falcon.HTTP_200
|
resp.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue