Skip to content

Commit

Permalink
#41: Add Distinct field filter and update precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Sep 5, 2019
1 parent a217699 commit cb67f07
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,13 @@ class QueryFilter(ABC):
def precedence(self):
pass


@abstractmethod
def apply_filter(self, query):
pass


class WhereFilter(QueryFilter):
precedence = 0
precedence = 1

def __init__(self, field, value, operation):
self.field = field
Expand All @@ -149,8 +148,15 @@ def apply_filter(self, query):
raise BadFilterError(f" Bad operation given to where filter. operation: {self.operation}")


class DistinctFieldFilter(QueryFilter):
precedence = 0

def apply_filter(self, query):
pass


class OrderFilter(QueryFilter):
precedence = 1
precedence = 2

def __init__(self, field, direction):
self.field = field
Expand All @@ -166,7 +172,7 @@ def apply_filter(self, query):


class SkipFilter(QueryFilter):
precedence = 2
precedence = 3

def __init__(self, skip_value):
self.skip_value = skip_value
Expand All @@ -176,7 +182,7 @@ def apply_filter(self, query):


class LimitFilter(QueryFilter):
precedence = 3
precedence = 4

def __init__(self, limit_value):
self.limit_value = limit_value
Expand All @@ -186,7 +192,7 @@ def apply_filter(self, query):


class IncludeFilter(QueryFilter):
precedence = 4
precedence = 5

def __init__(self, included_filters):
self.included_filters = included_filters
Expand Down Expand Up @@ -227,6 +233,7 @@ class FilterOrderHandler(object):
"""
The FilterOrderHandler takes in filters, sorts them according to the order of operations, then applies them.
"""

def __init__(self):
self.filters = []

Expand Down

0 comments on commit cb67f07

Please sign in to comment.