77 CosmosDBModel ,
88 CosmosDBDao ,
99 CosmosDBRepository ,
10+ CustomError ,
1011)
1112from time_tracker_api .database import CRUDDao , APICosmosDBDao
1213from typing import List , Callable
1314from commons .data_access_layer .database import EventContext
1415from utils .enums .status import Status
1516from utils .query_builder import CosmosDBQueryBuilder
16- from commons .data_access_layer .file_stream import FileStream
17+ from commons .data_access_layer .file import FileStream
18+
1719
1820class ActivityDao (CRUDDao ):
1921 pass
@@ -118,16 +120,27 @@ def find_all_from_blob_storage(
118120 self ,
119121 event_context : EventContext ,
120122 mapper : Callable = None ,
123+ activity_id : str = None ,
121124 file_name : str = "activity.json" ,
122- ):
125+ ):
123126 tenant_id_value = self .find_partition_key_value (event_context )
124127 function_mapper = self .get_mapper_or_dict (mapper )
125128 if tenant_id_value is None :
126- return []
127-
128- fs = FileStream ("storageaccounteystr82c5" , " tt-common-files" )
129+ return [{ "result" : "error" , "message" : "tenant_id is None" } ]
130+
131+ fs = FileStream ("tt-common-files" )
129132 result = fs .get_file_stream (file_name )
130- return list (map (function_mapper , json .load (result ))) if result is not None else []
133+ result_json = list (map (function_mapper , json .loads (
134+ result ))) if result is not None else []
135+ if activity_id is not None :
136+ result_json = [
137+ activity
138+ for activity in result_json
139+ if activity .id == activity_id
140+ ]
141+
142+ return result_json
143+
131144
132145class ActivityCosmosDBDao (APICosmosDBDao , ActivityDao ):
133146 def __init__ (self , repository ):
@@ -143,7 +156,7 @@ def get_all_with_id_in_list(
143156 activity_ids ,
144157 )
145158
146- def get_all (
159+ def get_all_v1 (
147160 self ,
148161 conditions : dict = None ,
149162 activities_id : List = None ,
@@ -162,11 +175,25 @@ def get_all(
162175 )
163176 return activities
164177
165- def get_all_test (self , conditions : dict = None ) -> list :
178+ def get_all (self , ** kwargs ) -> list :
166179 event_ctx = self .create_event_context ("read-many" )
167- activities = self .repository .find_all_from_blob_storage (event_context = event_ctx )
180+ activities = self .repository .find_all_from_blob_storage (
181+ event_context = event_ctx
182+ )
168183 return activities
169184
185+ def get (self , id : str = None ) -> list :
186+ event_ctx = self .create_event_context ("read-many" )
187+ activities = self .repository .find_all_from_blob_storage (
188+ event_context = event_ctx ,
189+ activity_id = id
190+ )
191+
192+ if len (activities ) > 0 :
193+ return activities [0 ]
194+ else :
195+ raise CustomError (404 , "It was not found" )
196+
170197 def create (self , activity_payload : dict ):
171198 event_ctx = self .create_event_context ('create' )
172199 activity_payload ['status' ] = Status .ACTIVE .value
0 commit comments