Skip to content

Commit

Permalink
feat: implement nin operator #297
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Jan 19, 2022
1 parent 1b14214 commit 00dbba5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions datagateway_api/src/datagateway_api/icat/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ def create_filter(self):
where_filter = self.create_condition(self.field, "in", self.value)
elif self.operation == "inq":
self.operation = "in"
where_filter = self.create_filter()
elif self.operation == "nin":
# Convert self.value into a string with brackets equivalent to tuple format.
# Cannot convert straight to tuple as single element tuples contain a
# trailing comma which Python ICAT/JPQL doesn't accept
self.value = str(self.value).replace("[", "(").replace("]", ")")

# DataGateway Search can send requests with blank lists. Adding NULL to the
# filter prevents the API from returning a 500. An empty list will be
# returned instead, equivalent to the DB backend
if self.value == "()":
self.value = "(NULL)"

where_filter = self.create_condition(self.field, "not in", self.value)
elif self.operation == "between":
where_filter = self.create_condition(
self.field, "between", f"'{self.value[0]}' and '{self.value[1]}'",
Expand Down

0 comments on commit 00dbba5

Please sign in to comment.