Skip to content

Commit

Permalink
fix: make get by pid endpoints return data in PaNOSC format #266
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Feb 2, 2022
1 parent efdc2a6 commit 0de2b5b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions datagateway_api/src/search_api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from datagateway_api.src.common.exceptions import MissingRecordError
from datagateway_api.src.common.filter_order_handle import FilterOrderHandler
from datagateway_api.src.common.filter_order_handler import FilterOrderHandler
from datagateway_api.src.datagateway_api.icat.filters import PythonICATIncludeFilter
from datagateway_api.src.search_api.filters import SearchAPIWhereFilter
import datagateway_api.src.search_api.models as models
Expand Down Expand Up @@ -87,6 +87,15 @@ def get_with_pid(entity_name, pid, filters):

filters.append(SearchAPIWhereFilter("pid", pid, "eq"))

icat_relations = mappings.get_icat_relations_for_panosc_non_related_fields(
entity_name,
)

# Remove any duplicate ICAT relations
icat_relations = list(dict.fromkeys(icat_relations))
if icat_relations:
filters.append(PythonICATIncludeFilter(icat_relations))

query = SearchAPIQuery(entity_name)

filter_handler = FilterOrderHandler()
Expand All @@ -100,7 +109,11 @@ def get_with_pid(entity_name, pid, filters):
if not icat_query_data:
raise MissingRecordError("No result found")
else:
return icat_query_data[0]
panosc_model = getattr(models, entity_name)
panosc_record = panosc_model.from_icat(icat_query_data[0], icat_relations).json(
by_alias=True,
)
return json.loads(panosc_record)


@client_manager
Expand Down

0 comments on commit 0de2b5b

Please sign in to comment.