Skip to content

Commit

Permalink
#136: Add support for delete entity by ID on new backend
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Jul 22, 2020
1 parent 8a1728b commit f072c1d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions common/python_icat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
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, update_entity_by_id
refresh_client_session, get_entity_by_id, update_entity_by_id, \
delete_entity_by_id
from common.config import config
from common.exceptions import AuthenticationError
from common.models.db_models import SESSION
Expand Down Expand Up @@ -85,7 +86,7 @@ def get_with_id(self, session_id, table, id):
@requires_session_id
@queries_records
def delete_with_id(self, session_id, table, id):
pass
return delete_entity_by_id(self.client, table.__name__, id)

@requires_session_id
@queries_records
Expand Down
18 changes: 17 additions & 1 deletion common/python_icat_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from icat.query import Query
from icat.exception import ICATSessionError
from common.exceptions import AuthenticationError, BadRequestError
from common.exceptions import AuthenticationError, BadRequestError, MissingRecordError

log = logging.getLogger()

Expand Down Expand Up @@ -245,6 +245,22 @@ def get_entity_by_id(client, table_name, id, return_json_formattable_data):
return entity_by_id_data


def delete_entity_by_id(client, table_name, id):
"""
Deletes a record of a given ID of the specified entity
:param client: ICAT client containing an authenticated user
:type client: :class:`icat.client.Client`
:param table_name: Table name to extract which entity to delete
:type table_name: :class:`str`
:param id: ID number of the entity to delete
:type id: :class:`int`
"""

entity_id_data = get_entity_by_id(client, table_name, id, False)
client.delete(entity_id_data[0])


def update_entity_by_id(client, table_name, id, new_data):
"""
Gets a record of a given ID of the specified entity
Expand Down

0 comments on commit f072c1d

Please sign in to comment.