Skip to content

Commit

Permalink
#34: Create ISISInvestigationsQuery class
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Aug 22, 2019
1 parent f55879c commit c8e85c4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sqlalchemy import asc, desc

from common.exceptions import MissingRecordError, BadFilterError, BadRequestError
from common.models.db_models import INVESTIGATIONUSER, INVESTIGATION
from common.session_manager import session_manager

log = logging.getLogger()
Expand Down Expand Up @@ -371,3 +372,20 @@ def patch_entities(table, json_list):
raise BadRequestError(f" Bad request made, request: {json_list}")

return results


class ISISInvestigationsQuery(ReadQuery):
"""
The query class used for the /users/<:id>/investigations endpoint
"""

def __init__(self, user_id):
super().__init__(INVESTIGATIONUSER)
self.base_query = self.base_query.join(INVESTIGATION).filter(INVESTIGATIONUSER.USER_ID == user_id)

def get_all_results(self):
return list(map(lambda x: x.INVESTIGATION, super().get_all_results()))

def get_single_result(self):
return list(map(lambda x: x.INVESTIGATION, super().get_single_result()))

0 comments on commit c8e85c4

Please sign in to comment.