modify the ticket agent list api

pull/141/MERGE^2
hyh123a 2022-04-18 21:40:02 +08:00
parent 0aa5db7547
commit b9b0264837
2 changed files with 35 additions and 4 deletions

View File

@ -113,7 +113,7 @@ api.add_route('/ticket/apply/{id_}',
ticket.TicketApplicationCollection()) ticket.TicketApplicationCollection())
# Get Ticket List: My Agent # Get Ticket List: My Agent
api.add_route('/ticket/agent/list', api.add_route('/ticket/list/agent',
ticket.TicketAgentListCollection()) ticket.TicketAgentListCollection())
######################################################################################################################## ########################################################################################################################
# Routes for System Core # Routes for System Core

View File

@ -304,7 +304,37 @@ class TicketAgentListCollection:
resp.status = falcon.HTTP_200 resp.status = falcon.HTTP_200
@staticmethod @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) cnx = mysql.connector.connect(**config.loonflow)
cursor = cnx.cursor() cursor = cnx.cursor()
@ -332,8 +362,9 @@ class TicketAgentListCollection:
query = (" SELECT id, title, workflow_id, sn, state_id, creator, gmt_created, gmt_modified " query = (" SELECT id, title, workflow_id, sn, state_id, creator, gmt_created, gmt_modified "
" FROM ticket_ticketrecord " " FROM ticket_ticketrecord "
" ORDER BY id DESC") " WHERE participant = %s "
cursor.execute(query) " ORDER BY id DESC ")
cursor.execute(query, (user_name, ))
rows = cursor.fetchall() rows = cursor.fetchall()
cursor.close() cursor.close()
cnx.close() cnx.close()