Skip to content

Commit bd17303

Browse files
committed
refactor: TT-182 create method to get all projects with list of ids
1 parent 7faa022 commit bd17303

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

time_tracker_api/projects/projects_model.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
create_dao as customers_create_dao,
1414
)
1515
from time_tracker_api.customers.customers_model import CustomerCosmosDBModel
16-
16+
from utils.query_builder import CosmosDBQueryBuilder
1717
from utils.extend_model import add_customer_name_to_projects
1818

1919

@@ -65,7 +65,32 @@ def __init__(self):
6565
partition_key_attribute='tenant_id',
6666
mapper=ProjectCosmosDBModel,
6767
)
68-
68+
69+
def find_all_with_id_in_list(
70+
self,
71+
event_context: EventContext,
72+
ids_list: List[str] = None,
73+
customers_ids_list: List[str] = None,
74+
visible_only=True,
75+
mapper: Callable = None,
76+
):
77+
query_builder = (CosmosDBQueryBuilder()
78+
.add_sql_in_condition("id",ids_list)
79+
.add_sql_in_condition("customer_id",customers_ids_list)
80+
.add_sql_visibility_condition(visibility_only)
81+
.build()
82+
)
83+
query_str = query_builder.get_query()
84+
tenant_id_value = self.find_partition_key_value(event_context)
85+
86+
result = self.container.query_items(
87+
query=query_str,
88+
partition_key=tenant_id_value,
89+
)
90+
function_mapper = self.get_mapper_or_dict(mapper)
91+
return list(map(function_mapper, result))
92+
93+
6994
def find_all_with_customer_id_in_list(
7095
self,
7196
event_context: EventContext,
@@ -124,6 +149,11 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
124149
add_customer_name_to_projects(projects, customers)
125150
return projects
126151

152+
def get_all_with_id_in_list(self,id_list,):
153+
event_ctx = self.create_event_context("read-many")
154+
return self.repository.find_all_with_id_in_list(event_ctx, id_list)
155+
156+
127157

128158
def create_dao() -> ProjectDao:
129159
repository = ProjectCosmosDBRepository()

0 commit comments

Comments
 (0)