From a61977495ed294c90104c332377d0392d2bf41f4 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Mon, 29 Jun 2020 18:38:19 +0200 Subject: Add individual trace endpoint --- .../opendc/api/v2/traces/traceId/endpoint.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'web-server/opendc/api/v2/traces/traceId/endpoint.py') diff --git a/web-server/opendc/api/v2/traces/traceId/endpoint.py b/web-server/opendc/api/v2/traces/traceId/endpoint.py index f6442a31..672e256c 100644 --- a/web-server/opendc/api/v2/traces/traceId/endpoint.py +++ b/web-server/opendc/api/v2/traces/traceId/endpoint.py @@ -1,26 +1,14 @@ -from opendc.models_old.trace import Trace -from opendc.util import exceptions +from opendc.models.trace import Trace from opendc.util.rest import Response def GET(request): """Get this Trace.""" - # Make sure required parameters are there + request.check_required_parameters(path={'traceId': 'string'}) - try: - request.check_required_parameters(path={'traceId': 'int'}) + trace = Trace.from_id(request.params_path['traceId']) - except exceptions.ParameterError as e: - return Response(400, str(e)) + trace.check_exists() - # Instantiate a Trace and make sure it exists - - trace = Trace.from_primary_key((request.params_path['traceId'], )) - - if not trace.exists(): - return Response(404, '{} not found.'.format(trace)) - - # Return this Trace - - return Response(200, 'Successfully retrieved {}.'.format(trace), trace.to_JSON()) + return Response(200, f'Successfully retrieved trace.', trace.obj) -- cgit v1.2.3