mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-24 16:24:32 +00:00
First attempt at converting "sig" to "activity" for v3
This commit is contained in:
@@ -22,7 +22,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class APILookupCallHandler(tornado.web.RequestHandler):
|
||||
"""API request handler for /api/v2/lookup/call"""
|
||||
"""API request handler for /api/v3/lookup/call"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -63,7 +63,7 @@ class APILookupCallHandler(tornado.web.RequestHandler):
|
||||
|
||||
|
||||
class APILookupActivityRefHandler(tornado.web.RequestHandler):
|
||||
"""API request handler for /api/v2/lookup/sigref"""
|
||||
"""API request handler for /api/v3/lookup/activityref"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -79,16 +79,16 @@ class APILookupActivityRefHandler(tornado.web.RequestHandler):
|
||||
# reduce that to just the first entry, and convert bytes to string
|
||||
query_params = {k: v[0].decode("utf-8") for k, v in self.request.arguments.items()}
|
||||
|
||||
# "sig" and "id" query params must exist, the activity must be known, and if we have a reference regex for
|
||||
# "activity" and "id" query params must exist, the activity must be known, and if we have a reference regex for
|
||||
# that activity, the provided id must match it.
|
||||
if "sig" in query_params and "id" in query_params:
|
||||
activity = str(query_params.get("sig")).upper()
|
||||
if "activity" in query_params and "id" in query_params:
|
||||
activity = str(query_params.get("activity")).upper()
|
||||
ref_id = str(query_params.get("id")).upper()
|
||||
if get_activity_by_name(activity):
|
||||
if not get_ref_regex_for_activity(activity) or re.match(
|
||||
get_ref_regex_for_activity(activity), ref_id
|
||||
):
|
||||
data = populate_missing_activity_ref_info(ActivityRef(id=ref_id, sig=activity))
|
||||
data = populate_missing_activity_ref_info(ActivityRef(id=ref_id, activity=activity))
|
||||
self.write(safe_json_dumps(data))
|
||||
|
||||
else:
|
||||
@@ -99,10 +99,10 @@ class APILookupActivityRefHandler(tornado.web.RequestHandler):
|
||||
)
|
||||
self.set_status(422)
|
||||
else:
|
||||
self.write(safe_json_dumps(f"Error - sig '{activity}' is not known."))
|
||||
self.write(safe_json_dumps(f"Error - activity '{activity}' is not known."))
|
||||
self.set_status(422)
|
||||
else:
|
||||
self.write(safe_json_dumps("Error - sig and id must be provided"))
|
||||
self.write(safe_json_dumps("Error - activity and id must be provided"))
|
||||
self.set_status(422)
|
||||
|
||||
except Exception:
|
||||
@@ -115,7 +115,7 @@ class APILookupActivityRefHandler(tornado.web.RequestHandler):
|
||||
|
||||
|
||||
class APILookupGridHandler(tornado.web.RequestHandler):
|
||||
"""API request handler for /api/v2/lookup/grid"""
|
||||
"""API request handler for /api/v3/lookup/grid"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user