-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add in
SearchAPIQueryFilterFactory
#259
- Added in a generic `QueryFilterFactory` object which inherits from the search API and DataGateway API versions - Also fixed imports of the DataGateway API specific implementation
- Loading branch information
1 parent
04d92f7
commit bbc9412
Showing
6 changed files
with
69 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from abc import abstractstaticmethod | ||
|
||
|
||
class QueryFilterFactory(object): | ||
@abstractstaticmethod | ||
def get_query_filter(request_filter): | ||
""" | ||
Given a filter, return a matching Query filter object | ||
:param request_filter: The filter to create the QueryFilter for | ||
:type request_filter: :class:`dict` | ||
:return: The QueryFilter object created | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
|
||
from datagateway_api.common.base_query_filter_factory import QueryFilterFactory | ||
from datagateway_api.common.exceptions import FilterError | ||
|
||
log = logging.getLogger() | ||
|
||
|
||
class SearchAPIQueryFilterFactory(QueryFilterFactory): | ||
@staticmethod | ||
def get_query_filter(request_filter): | ||
query_param_name = list(request_filter)[0].lower() | ||
query_filters = [] | ||
|
||
if query_param_name == "filter": | ||
log.debug( | ||
f"Filter: {request_filter['filter']}, Type: {type(request_filter['filter'])})" | ||
) | ||
for filter_name, filter_input in request_filter["filter"].items(): | ||
if filter_name == "where": | ||
pass | ||
elif filter_name == "include": | ||
pass | ||
elif filter_name == "limit": | ||
pass | ||
elif filter_name == "skip": | ||
pass | ||
else: | ||
raise FilterError( | ||
"No valid filter name given within filter query param" | ||
) | ||
|
||
return query_filters | ||
else: | ||
raise FilterError(f"Bad filter, please check input: {request_filter}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters