diff --git a/common/python_icat_backend.py b/common/python_icat_backend.py index 59a965c5..0e41fb56 100644 --- a/common/python_icat_backend.py +++ b/common/python_icat_backend.py @@ -6,7 +6,7 @@ from common.backend import Backend from common.helpers import queries_records from common.python_icat_helpers import requires_session_id, get_session_details_helper, logout_icat_client, \ - refresh_client_session, get_entity_by_id + refresh_client_session, get_entity_by_id, update_entity_by_id from common.config import config from common.exceptions import AuthenticationError from common.models.db_models import SESSION @@ -90,7 +90,7 @@ def delete_with_id(self, session_id, table, id): @requires_session_id @queries_records def update_with_id(self, session_id, table, id, data): - pass + return update_entity_by_id(self.client, table.__name__, id, data) @requires_session_id @queries_records diff --git a/common/python_icat_helpers.py b/common/python_icat_helpers.py index a497daa6..173c2c9a 100644 --- a/common/python_icat_helpers.py +++ b/common/python_icat_helpers.py @@ -131,14 +131,20 @@ def get_entity_by_id(client, table, id): for entity_name in entity_names: lowercase_name = entity_name.lower() - if lowercase_name == lowercase_table_name: - selected_entity = entity_name +def update_entity_by_id(client, table_name, id, new_data): + """ + Updates certain attributes Gets a record of a given ID of the specified entity - # Raise a 400 if a valid entity cannot be found - if selected_entity is None: - raise BadRequestError(f"Bad request made, cannot find {table.__name__} entity within Python ICAT") + :param client: ICAT client containing an authenticated user + :type client: :class:`icat.client.Client` + :param table_name: Table name to extract which entity to use + :type table_name: TODO + :param id: ID number of the entity to retrieve + :type id: :class:`int` + :param new_data: JSON from request body providing new data to update the record with the + specified ID + """ - id_query = construct_icat_query(client, selected_entity, id_condition) - entity_by_id_data = execute_icat_query(client, id_query) + pass return entity_by_id_data diff --git a/src/resources/entities/entity_endpoint.py b/src/resources/entities/entity_endpoint.py index f8c2867f..4779f929 100644 --- a/src/resources/entities/entity_endpoint.py +++ b/src/resources/entities/entity_endpoint.py @@ -216,7 +216,7 @@ def delete(self, id): def patch(self, id): session_id = get_session_id_from_auth_header() backend.update_with_id(session_id, table, id, request.json) - return backend.get_with_id(session_id, table, id).to_dict(), 200 + return backend.get_with_id(session_id, table, id), 200 patch.__doc__ = f""" ---