Skip to content

Commit

Permalink
#34: Add get investigation count function
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Aug 22, 2019
1 parent 31677c3 commit 9e8e0e5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ def get_investigations_for_user(user_id, filters):
finally:
query.session.close()


class ISISInvestigationsCountQuery(CountQuery):
"""
The query class used for /users/<:id>/investigations/count
Expand All @@ -449,3 +450,15 @@ class ISISInvestigationsCountQuery(CountQuery):
def __init__(self, user_id):
super().__init__(INVESTIGATIONUSER)
self.base_query = self.base_query.join(INVESTIGATION).filter(INVESTIGATIONUSER.USER_ID == user_id)


def get_investigations_for_user_count(user_id, filters):
count_query = ISISInvestigationsCountQuery(user_id)
filter_handler = FilterOrderHandler()
for query_filter in filters:
if len(query_filter) == 0:
pass
else:
filter_handler.add_filter(QueryFilterFactory.get_query_filter(query_filter))
filter_handler.apply_filters(count_query)
return count_query.get_count()

0 comments on commit 9e8e0e5

Please sign in to comment.