Skip to content

Commit

Permalink
#209: Fix API on DB backend
Browse files Browse the repository at this point in the history
- The client pool design wasn't working on DB backend, but now it does
  • Loading branch information
MRichards99 committed Apr 6, 2021
1 parent 33bdcd1 commit b0350c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions datagateway_api/common/database/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DatabaseBackend(Backend):
Class that contains functions to access and modify data in an ICAT database directly
"""

def login(self, credentials):
def login(self, credentials, **kwargs):
if credentials["username"] == "user" and credentials["password"] == "password":
session_id = str(uuid.uuid1())
insert_row_into_table(
Expand All @@ -48,84 +48,84 @@ def login(self, credentials):
raise AuthenticationError("Username and password are incorrect")

@requires_session_id
def get_session_details(self, session_id):
def get_session_details(self, session_id, **kwargs):
return get_row_by_id(SESSION, session_id).to_dict()

@requires_session_id
def refresh(self, session_id):
def refresh(self, session_id, **kwargs):
return session_id

@requires_session_id
@queries_records
def logout(self, session_id):
def logout(self, session_id, **kwargs):
return delete_row_by_id(SESSION, session_id)

@requires_session_id
@queries_records
def get_with_filters(self, session_id, entity_type, filters):
def get_with_filters(self, session_id, entity_type, filters, **kwargs):
table = get_entity_object_from_name(entity_type)
return get_rows_by_filter(table, filters)

@requires_session_id
@queries_records
def create(self, session_id, entity_type, data):
def create(self, session_id, entity_type, data, **kwargs):
table = get_entity_object_from_name(entity_type)
return create_rows_from_json(table, data)

@requires_session_id
@queries_records
def update(self, session_id, entity_type, data):
def update(self, session_id, entity_type, data, **kwargs):
table = get_entity_object_from_name(entity_type)
return patch_entities(table, data)

@requires_session_id
@queries_records
def get_one_with_filters(self, session_id, entity_type, filters):
def get_one_with_filters(self, session_id, entity_type, filters, **kwargs):
table = get_entity_object_from_name(entity_type)
return get_first_filtered_row(table, filters)

@requires_session_id
@queries_records
def count_with_filters(self, session_id, entity_type, filters):
def count_with_filters(self, session_id, entity_type, filters, **kwargs):
table = get_entity_object_from_name(entity_type)
return get_filtered_row_count(table, filters)

@requires_session_id
@queries_records
def get_with_id(self, session_id, entity_type, id_):
def get_with_id(self, session_id, entity_type, id_, **kwargs):
table = get_entity_object_from_name(entity_type)
return get_row_by_id(table, id_).to_dict()

@requires_session_id
@queries_records
def delete_with_id(self, session_id, entity_type, id_):
def delete_with_id(self, session_id, entity_type, id_, **kwargs):
table = get_entity_object_from_name(entity_type)
return delete_row_by_id(table, id_)

@requires_session_id
@queries_records
def update_with_id(self, session_id, entity_type, id_, data):
def update_with_id(self, session_id, entity_type, id_, data, **kwargs):
table = get_entity_object_from_name(entity_type)
return update_row_from_id(table, id_, data)

@requires_session_id
@queries_records
def get_facility_cycles_for_instrument_with_filters(
self, session_id, instrument_id, filters,
self, session_id, instrument_id, filters, **kwargs,
):
return get_facility_cycles_for_instrument(instrument_id, filters)

@requires_session_id
@queries_records
def get_facility_cycles_for_instrument_count_with_filters(
self, session_id, instrument_id, filters,
self, session_id, instrument_id, filters, **kwargs,
):
return get_facility_cycles_for_instrument_count(instrument_id, filters)

@requires_session_id
@queries_records
def get_investigations_for_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters,
self, session_id, instrument_id, facilitycycle_id, filters, **kwargs,
):
return get_investigations_for_instrument_in_facility_cycle(
instrument_id, facilitycycle_id, filters,
Expand All @@ -134,7 +134,7 @@ def get_investigations_for_instrument_facility_cycle_with_filters(
@requires_session_id
@queries_records
def get_investigation_count_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters,
self, session_id, instrument_id, facilitycycle_id, filters, **kwargs,
):
return get_investigations_for_instrument_in_facility_cycle_count(
instrument_id, facilitycycle_id, filters,
Expand Down
4 changes: 2 additions & 2 deletions datagateway_api/src/api_start_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def create_api_endpoints(flask_app, api, spec):

backend = create_backend(backend_type)

icat_client_pool = None
if backend_type == "python_icat":
# Create client pool
# TODO - Protect against other backends
icat_client_pool = create_client_pool()

for entity_name in endpoints:
Expand Down Expand Up @@ -112,7 +112,7 @@ def create_api_endpoints(flask_app, api, spec):

# Table specific endpoints
instrument_facility_cycle_resource = instrument_facility_cycles_endpoint(
backend, client_pool=icat_client_pool
backend, client_pool=icat_client_pool,
)
api.add_resource(
instrument_facility_cycle_resource, "/instruments/<int:id_>/facilitycycles",
Expand Down

0 comments on commit b0350c9

Please sign in to comment.