Skip to content

Commit

Permalink
feat: Update DMS provider to expect multiple sortable properties.
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Munim Adil committed Jun 25, 2024
1 parent 1810785 commit a87b25f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions msc_pygeoapi/provider/msc_dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]}'
Expand Down

0 comments on commit a87b25f

Please sign in to comment.