From 1049a5f82feef3f5909440e4e928a43f969c4219 Mon Sep 17 00:00:00 2001 From: Matthew Richards Date: Wed, 24 Nov 2021 17:19:42 +0000 Subject: [PATCH] add helper functions for each endpoint type for search API #258 --- .../src/resources/search_api_endpoints.py | 37 ++++++--------- datagateway_api/src/search_api/helpers.py | 45 +++++++++++++++++-- 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/datagateway_api/src/resources/search_api_endpoints.py b/datagateway_api/src/resources/search_api_endpoints.py index 07c2aa85..282e99e7 100644 --- a/datagateway_api/src/resources/search_api_endpoints.py +++ b/datagateway_api/src/resources/search_api_endpoints.py @@ -1,9 +1,14 @@ from flask_restful import Resource +from datagateway_api.src.search_api.helpers import ( + get_count, + get_files, + get_files_count, + get_search, + get_with_id, +) + -# TODO - Might need kwargs on get_search_endpoint(), get_single_endpoint(), -# get_number_count_endpoint(), get_files_endpoint(), get_number_count_files_endpoint() -# for client handling? def get_search_endpoint(name): """ TODO - Add docstring @@ -11,19 +16,7 @@ def get_search_endpoint(name): class Endpoint(Resource): def get(self): - """ - TODO - Need to return similar to - return ( - backend.get_with_filters( - get_session_id_from_auth_header(), - entity_type, - get_filters_from_query_string(), - **kwargs, - ), - 200, - ) - """ - pass + return get_search(name), 200 # TODO - Add `get.__doc__` @@ -38,8 +31,7 @@ def get_single_endpoint(name): class EndpointWithID(Resource): def get(self, pid): - # TODO - Add return - pass + return get_with_id(name, pid), 200 # TODO - Add `get.__doc__` @@ -54,8 +46,7 @@ def get_number_count_endpoint(name): class CountEndpoint(Resource): def get(self): - # TODO - Add return - pass + return get_count(name), 200 # TODO - Add `get.__doc__` @@ -70,8 +61,7 @@ def get_files_endpoint(name): class FilesEndpoint(Resource): def get(self, pid): - # TODO - Add return - pass + return get_files(name), 200 # TODO - Add `get.__doc__` @@ -86,8 +76,7 @@ def get_number_count_files_endpoint(name): class CountFilesEndpoint(Resource): def get(self, pid): - # TODO - Add return - pass + return get_files_count(name, pid) # TODO - Add `get.__doc__` diff --git a/datagateway_api/src/search_api/helpers.py b/datagateway_api/src/search_api/helpers.py index ca6a72a5..fae85878 100644 --- a/datagateway_api/src/search_api/helpers.py +++ b/datagateway_api/src/search_api/helpers.py @@ -1,3 +1,42 @@ -""" -Code to store helper functions to deal with the endpoints, like for DataGateway API -""" +import logging + +from datagateway_api.src.search_api.session_handler import ( + SessionHandler, + client_manager, +) + + +log = logging.getLogger() + + +# TODO - Make filters mandatory, if no filters are in a request an empty list will be +# given to these functions +@client_manager +def get_search(entity_name, filters=None): + # TODO - Remove this debug logging when implementing the endpoints, this is just to + # show the client handling works + log.debug( + "Client: %s, Session ID: %s", + SessionHandler.client, + SessionHandler.client.sessionId, + ) + + +@client_manager +def get_with_id(entity_name, id, filters=None): + pass + + +@client_manager +def get_count(entity_name, filters=None): + pass + + +@client_manager +def get_files(entity_name, filters=None): + pass + + +@client_manager +def get_files_count(entity_name, id, filters=None): + pass