From a76f89fb69bafc21c4dddffbae1ea34c620abd88 Mon Sep 17 00:00:00 2001 From: Munim Adil Date: Mon, 24 Jun 2024 17:49:21 +0000 Subject: [PATCH] feat: Update DMS provider to expect multiple sortable properties. The `sortby` mechanism in the query method has been updated to expect sortable properties in a collection rather than as a single item, enabling multiple sortable properties. This has been done by adding a new `sortables` list member to the `MSCDMSCoreAPIProvider` class. This attribute is set to a `sortables` definition if it exists as a list in `msc-pygeoapi-config.yml`. Otherwise, it stores just the `time_field`. --- msc_pygeoapi/provider/msc_dms.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/msc_pygeoapi/provider/msc_dms.py b/msc_pygeoapi/provider/msc_dms.py index 63a069d8..0f09b5fe 100644 --- a/msc_pygeoapi/provider/msc_dms.py +++ b/msc_pygeoapi/provider/msc_dms.py @@ -100,6 +100,9 @@ def __init__(self, provider_def): LOGGER.debug('Grabbing field information') self.fields = self.get_fields() + self.sortables = [sortable for sortable + in provider_def.get('sortables', [self.time_field])] + def get_fields(self): """ Get provider field information (names, types) @@ -243,8 +246,9 @@ def query( sort_by_values = [] for sort in sortby: # only allow sort on time_field - if sort['property'] != self.time_field: - msg = f'Sorting only enabled for {self.time_field}' + if sort['property'] not in self.sortables: + msg = f'Sorting only enabled for {self.sortables}' + LOGGER.error(msg) raise ProviderQueryError(msg) LOGGER.debug(f'processing sort object: {sort}') sort_property = f'{sort["order"]}properties.{sort["property"]}'