@@ -68,10 +68,10 @@ def __init__(self):
6868 mapper = ProjectCosmosDBModel ,
6969 )
7070
71- def find_all_v2 (
71+ def find_all (
7272 self ,
7373 event_context : EventContext ,
74- project_ids : List [str ],
74+ project_ids : List [str ] = None ,
7575 customer_ids : List [str ] = None ,
7676 visible_only = True ,
7777 mapper : Callable = None ,
@@ -97,7 +97,9 @@ class ProjectCosmosDBDao(APICosmosDBDao, ProjectDao):
9797 def __init__ (self , repository ):
9898 CosmosDBDao .__init__ (self , repository )
9999
100- def get_all (self , conditions : dict = None , ** kwargs ) -> list :
100+ def get_all (
101+ self , conditions : dict = None , project_ids : List = None , ** kwargs
102+ ) -> list :
101103 """
102104 Get all the projects an active client has
103105 :param (dict) conditions: Conditions for querying the database
@@ -110,29 +112,27 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
110112 max_count = kwargs .get ('max_count' , None )
111113 )
112114
115+ # TODO: evaluate another approach in order that memory filtering will be make in Database instead
113116 customers_id = [
114117 customer .id
115118 for customer in customers
116119 if customer .status == 'active'
117120 ]
118121 conditions = conditions if conditions else {}
119- custom_condition = "c.customer_id IN {}" .format (
120- str (tuple (customers_id ))
122+ customers_ids = [v for k , v in conditions .items ()]
123+ customers_ids = (
124+ customers_ids + customers_id if project_ids else customers_ids
125+ )
126+
127+ projects = self .repository .find_all (
128+ event_context = event_ctx ,
129+ project_ids = project_ids ,
130+ customer_ids = customers_ids ,
121131 )
122- # TODO this must be refactored to be used from the utils module ↑
123- if "custom_sql_conditions" in kwargs :
124- kwargs ["custom_sql_conditions" ].append (custom_condition )
125- else :
126- kwargs ["custom_sql_conditions" ] = [custom_condition ]
127- projects = self .repository .find_all (event_ctx , conditions , ** kwargs )
128132
129133 add_customer_name_to_projects (projects , customers )
130134 return projects
131135
132- def get_all_with_id_in_list (self , id_list ):
133- event_ctx = self .create_event_context ("read-many" )
134- return self .repository .find_all_v2 (event_ctx , id_list )
135-
136136
137137def create_dao () -> ProjectDao :
138138 repository = ProjectCosmosDBRepository ()
0 commit comments