|
13 | 13 | create_dao as customers_create_dao, |
14 | 14 | ) |
15 | 15 | from time_tracker_api.customers.customers_model import CustomerCosmosDBModel |
16 | | - |
| 16 | +from utils.query_builder import CosmosDBQueryBuilder |
17 | 17 | from utils.extend_model import add_customer_name_to_projects |
18 | 18 |
|
19 | 19 |
|
@@ -65,7 +65,32 @@ def __init__(self): |
65 | 65 | partition_key_attribute='tenant_id', |
66 | 66 | mapper=ProjectCosmosDBModel, |
67 | 67 | ) |
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 | + |
69 | 94 | def find_all_with_customer_id_in_list( |
70 | 95 | self, |
71 | 96 | event_context: EventContext, |
@@ -124,6 +149,11 @@ def get_all(self, conditions: dict = None, **kwargs) -> list: |
124 | 149 | add_customer_name_to_projects(projects, customers) |
125 | 150 | return projects |
126 | 151 |
|
| 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 | + |
127 | 157 |
|
128 | 158 | def create_dao() -> ProjectDao: |
129 | 159 | repository = ProjectCosmosDBRepository() |
|
0 commit comments