Skip to content

Commit

Permalink
add helper functions for each endpoint type for search API #258
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Nov 24, 2021
1 parent 46a1539 commit 1049a5f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
37 changes: 13 additions & 24 deletions datagateway_api/src/resources/search_api_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
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
"""

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__`

Expand All @@ -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__`

Expand All @@ -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__`

Expand All @@ -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__`

Expand All @@ -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__`

Expand Down
45 changes: 42 additions & 3 deletions datagateway_api/src/search_api/helpers.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1049a5f

Please sign in to comment.